SHARE
TWEET

Untitled

a guest May 24th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. # coding: utf-8
  3.  
  4. # -------------- #
  5. # impose booklet #
  6. # -------------- #
  7.  
  8. ### Modules
  9. from os import mkdir
  10. from os.path import basename, join, exists
  11. import drawBot as dB
  12.  
  13. ### Constants
  14. FROM_MM_TO_PT = 2.834627813
  15. CROP_LEN = 5*FROM_MM_TO_PT
  16. CROP_DIS = 2*FROM_MM_TO_PT
  17.  
  18. ### Variables - EDIT HERE!!!
  19. fileName = 'booklet/drafts/20190412_booklet_v02.pdf'
  20. sheetCanvas = 297*FROM_MM_TO_PT, 210*FROM_MM_TO_PT
  21. pagesPerSignature = 16
  22. outputFolder = 'imposed'
  23. marks = False
  24.  
  25. bleed = {
  26.     'ver': 5*FROM_MM_TO_PT,
  27.     'hor': 5*FROM_MM_TO_PT,
  28. }
  29.  
  30. ### Instructions
  31. inputPages = dB.numberOfPages(fileName)
  32. assert inputPages % 4 == 0, 'check the amount of input pages'
  33. assert inputPages % pagesPerSignature == 0, 'check the amount of input pages'
  34.  
  35. if exists(outputFolder) is False:
  36.     mkdir(outputFolder)
  37.  
  38. for signature in range(inputPages//pagesPerSignature):
  39.     startingPage = signature*pagesPerSignature
  40.     pages = list(range(startingPage+1, startingPage+pagesPerSignature+1))
  41.  
  42.     dB.newDrawing()
  43.     for eachPage in range(pagesPerSignature//2):
  44.         dB.newPage(*sheetCanvas)
  45.  
  46.         if eachPage % 2 == 1:
  47.             lftPageIndex = eachPage
  48.             rgtPageIndex = -(eachPage+1)
  49.         else:
  50.             rgtPageIndex = eachPage
  51.             lftPageIndex = -(eachPage+1)
  52.         lftPageNumber = pages[lftPageIndex]
  53.         rgtPageNumber = pages[rgtPageIndex]
  54.  
  55.         imgWdt, imgHgt = dB.imageSize(fileName)
  56.  
  57.         with dB.savedState():
  58.             dB.translate(dB.width()/2, dB.height()/2-imgHgt/2)
  59.             dB.image(fileName, (-imgWdt, 0), pageNumber=lftPageNumber)
  60.             dB.image(fileName, (0, 0), pageNumber=rgtPageNumber)
  61.  
  62.         if marks is True:
  63.             with dB.savedState():
  64.                 dB.cmykStroke(1, 1, 1, 1)
  65.                 dB.translate(dB.width()/2, dB.height()/2)
  66.  
  67.                 # crop marks
  68.                 for scaling in [(-1, -1), (1, -1), (-1, 1), (1, 1)]:
  69.                     with dB.savedState():
  70.                         dB.scale(*scaling)
  71.                         dB.translate(imgWdt-bleed['hor'], imgHgt/2-bleed['ver'])
  72.                         # btm lft
  73.                         pt1 = CROP_DIS,          0
  74.                         pt2 = CROP_DIS+CROP_LEN, 0
  75.  
  76.                         dB.line(pt1, pt2)   # hor
  77.                         pt3 = 0, CROP_DIS
  78.                         pt4 = 0, CROP_LEN+CROP_DIS
  79.                         dB.line(pt3, pt4)   # ver
  80.  
  81.                 # fold marks
  82.                 for scaling in [(1, 1), (1, -1)]:
  83.                     with dB.savedState():
  84.                         dB.scale(*scaling)
  85.                         pt5 = 0, imgHgt/2 - bleed['ver'] + CROP_DIS
  86.                         pt6 = 0, imgHgt/2 - bleed['ver'] + CROP_DIS + CROP_LEN
  87.                         dB.line(pt5, pt6)
  88.  
  89.     cleanFileName = basename(fileName).replace('.pdf', '')
  90.     dB.saveImage(join(outputFolder, f"{cleanFileName}_sign{signature+1:0>2d}.pdf"))
  91.     dB.endDrawing()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top