项目作者: tavinus

项目描述 :
Bash Script to Scale and Resize PDFs using Ghostscript
高级语言: Shell
项目地址: git://github.com/tavinus/pdfScale.git
创建时间: 2016-07-10T04:37:48Z
项目社区:https://github.com/tavinus/pdfScale

开源协议:

下载


pdfScale 2

Bash Script to scale and/or resize PDFs from the command line.
Uses ghostscript (gs) to create a scaled and/or resized version of the pdf input.

In scaling mode, the PDF paper size does not change, just the elements are scaled.
In resize mode, the PDF paper will be changed and fit-to-page will be applied.
In mixed mode, the PDF will first be resized then scaled with two Ghostscript calls.
A temporary file is used in mixed mode, at the target location.


If you want to support this project, you can do it here :coffee: :beer:

paypal-image


Example Runs

Better than explaining is showing it:

Checking File Information

  1. $ ./pdfScale.sh -i test.pdf
  2. pdfScale.sh v2.6.2 - Paper Sizes
  3. -------------+-----------------------------
  4. File | test.pdf
  5. Paper Type | A4 Portrait
  6. Pages | 4
  7. -------------+-----------------------------
  8. FIRST PAGE | WIDTH x HEIGHT
  9. Points | 595 x 842
  10. Millimeters | 210 x 297
  11. Inches | 8.3 x 11.7
  12. -------------+-----------------------------
  13. ALL PAGES | WIDTH x HEIGHT (pts)
  14. 1 | 595 x 842
  15. 2 | 595 x 842
  16. 3 | 595 x 842
  17. 4 | 595 x 842
  18. -------------+-----------------------------

Scale by 0.95 (-5%)

This also shows a very special case of a PDF file that has no /MediaBox defined. It is a dumb container of n-up binary PDF pages.

  1. Ggrep fails, then
  2. PDFInfo fails (not installed), then
  3. ImageMagick fails (not installed), then
  4. The Ghostscript PS script does the job

This was on CygWin64 @ Windows11 x64, MacOS would try mdls as well.

  1. $ ./pdfScale.sh -v ../input-nup.pdf
  2. pdfScale.sh v2.6.2 - Verbose Execution
  3. Single Task: Scale PDF Contents
  4. Dry-Run: FALSE
  5. Input File: ../input-nup.pdf
  6. Output File: ../input-nup.SCALED.pdf
  7. Explode PDF: Disabled
  8. Get Page Size: Adaptive Enabled
  9. Method: Grep
  10. Failed, trying next method
  11. Method: PDFInfo
  12. Failed, trying next method
  13. Method: ImageMagick's Identify
  14. Failed, trying next method
  15. Method: Ghostscript PS Script
  16. Page Range: None (all pages)
  17. Source Width: 842 postscript-points
  18. Source Height: 595 postscript-points
  19. Print Mode: Print ( auto/empty )
  20. Scale Factor: 0.95 (auto)
  21. Scale Percent: -5%
  22. Vert-Align: CENTER
  23. Hor-Align: CENTER
  24. Translation X: 22.16 = 22.16 + 0.00 (offset)
  25. Translation Y: 15.66 = 15.66 + 0.00 (offset)
  26. Background: No background (default)
  27. Final Status: File created successfully

Resize to A0 and Scale by 1.05 (+5%)

  1. $ ./pdfScale.sh -v -r a0 -s 1.05 ../mixsync_manual_v1-2-3.pdf
  2. pdfScale.sh v2.6.2 - Verbose Execution
  3. Mixed Tasks: Resize & Scale
  4. Dry-Run: FALSE
  5. Input File: ../mixsync_manual_v1-2-3.pdf
  6. Output File: ../mixsync_manual_v1-2-3.A0.SCALED.pdf
  7. Explode PDF: Disabled
  8. Get Page Size: Adaptive Enabled
  9. Method: Grep
  10. Page Range: None (all pages)
  11. Source Width: 842 postscript-points
  12. Source Height: 595 postscript-points
  13. Print Mode: Print ( auto/empty )
  14. Fit To Page: Enabled (default)
  15. Auto Rotate: PageByPage
  16. Flip Detect: Wrong orientation detected!
  17. Inverting Width <-> Height
  18. Run Resizing: A0 ( 3370 x 2384 ) pts
  19. New Width: 3370 postscript-points
  20. New Height: 2384 postscript-points
  21. Scale Factor: 1.05
  22. Scale Percent: +5%
  23. Vert-Align: CENTER
  24. Hor-Align: CENTER
  25. Translation X: -80.24 = -80.24 + 0.00 (offset)
  26. Translation Y: -56.76 = -56.76 + 0.00 (offset)
  27. Background: No background (default)
  28. Final Status: File created successfully

Resize to A3, Scale by 1.11 (+11%) and Explode the results

Exploding (splitting) will create a PDF file for each page, with the .Page#.pdf suffix

  1. $ ./pdfScale.sh -v -s 1.11 -r A3 -e ../mixsync_manual_v1-4-2.pdf
  2. pdfScale.sh v2.6.2 - Verbose Execution
  3. Mixed Tasks: Resize & Scale
  4. Dry-Run: FALSE
  5. Input File: ../mixsync_manual_v1-4-2.pdf
  6. Output File: ../mixsync_manual_v1-4-2.A3.SCALED.Page%d.pdf
  7. Explode PDF: Enabled
  8. Get Page Size: Adaptive Enabled
  9. Method: Grep
  10. Page Range: None (all pages)
  11. Source Width: 595 postscript-points
  12. Source Height: 842 postscript-points
  13. Print Mode: Print ( auto/empty )
  14. Fit To Page: Enabled (default)
  15. Auto Rotate: PageByPage
  16. Flip Detect: No change needed
  17. Run Resizing: A3 ( 842 x 1191 ) pts
  18. New Width: 842 postscript-points
  19. New Height: 1191 postscript-points
  20. Scale Factor: 1.11
  21. Scale Percent: +11%
  22. Vert-Align: CENTER
  23. Hor-Align: CENTER
  24. Translation X: -41.72 = -41.72 + 0.00 (offset)
  25. Translation Y: -59.01 = -59.01 + 0.00 (offset)
  26. Background: No background (default)
  27. Final Status: File created successfully

Resize to A2 and disables Auto-Rotation

  1. $ ./pdfScale.sh -v -r A2 -a none ../input.pdf
  2. pdfScale.sh v2.6.2 - Verbose Execution
  3. Single Task: Resize PDF Paper
  4. Dry-Run: FALSE
  5. Input File: ../input.pdf
  6. Output File: ../input.A2.pdf
  7. Explode PDF: Disabled
  8. Get Page Size: Adaptive Enabled
  9. Method: Grep
  10. Page Range: None (all pages)
  11. Source Width: 595 postscript-points
  12. Source Height: 842 postscript-points
  13. Print Mode: Print ( auto/empty )
  14. Scale Factor: Disabled (resize only)
  15. Fit To Page: Enabled (default)
  16. Auto Rotate: None
  17. Flip Detect: No change needed
  18. Run Resizing: A2 ( 1191 x 1684 ) pts
  19. Final Status: File created successfully

Resize to custom 200x300 mm, disable Flip-Detection and Scale by 0.95 (-5%)

  1. $ ./pdfScale.sh -v -v -r 'custom mm 200 300' -f disable -s 0.95 ../mixsync_manual_v1-2-3.pdf
  2. 2024-07-17:14:43:15 | pdfScale.sh v2.6.2 - Verbose Execution
  3. 2024-07-17:14:43:15 | Mixed Tasks: Resize & Scale
  4. 2024-07-17:14:43:15 | Dry-Run: FALSE
  5. 2024-07-17:14:43:15 | Input File: ../mixsync_manual_v1-2-3.pdf
  6. 2024-07-17:14:43:15 | Output File: ../mixsync_manual_v1-2-3.CUSTOM.SCALED.pdf
  7. 2024-07-17:14:43:15 | Explode PDF: Disabled
  8. 2024-07-17:14:43:15 | Get Page Size: Adaptive Enabled
  9. 2024-07-17:14:43:15 | Method: Grep
  10. 2024-07-17:14:43:15 | Page Range: None (all pages)
  11. 2024-07-17:14:43:16 | Source Width: 842 postscript-points
  12. 2024-07-17:14:43:16 | Source Height: 595 postscript-points
  13. 2024-07-17:14:43:16 | Print Mode: Print ( auto/empty )
  14. 2024-07-17:14:43:16 | Fit To Page: Enabled (default)
  15. 2024-07-17:14:43:16 | Auto Rotate: PageByPage
  16. 2024-07-17:14:43:16 | Flip Detect: Disabled
  17. 2024-07-17:14:43:16 | Run Resizing: CUSTOM ( 567 x 850 ) pts
  18. 2024-07-17:14:43:16 | New Width: 567 postscript-points
  19. 2024-07-17:14:43:16 | New Height: 850 postscript-points
  20. 2024-07-17:14:43:16 | Scale Factor: 0.95
  21. 2024-07-17:14:43:16 | Scale Percent: -5%
  22. 2024-07-17:14:43:16 | Vert-Align: CENTER
  23. 2024-07-17:14:43:16 | Hor-Align: CENTER
  24. 2024-07-17:14:43:16 | Translation X: 14.92 = 14.92 + 0.00 (offset)
  25. 2024-07-17:14:43:16 | Translation Y: 22.37 = 22.37 + 0.00 (offset)
  26. 2024-07-17:14:43:16 | Background: No background (default)
  27. 2024-07-17:14:43:17 | Final Status: File created successfully

Help info

  1. $ ./pdfScale.sh -h
  2. pdfScale.sh v2.6.2
  3. Usage: pdfScale.sh <inFile.pdf>
  4. pdfScale.sh -i <inFile.pdf>
  5. pdfScale.sh [-v] [-s <factor>] [-m <page-detection>] <inFile.pdf> [outfile.pdf]
  6. pdfScale.sh [-v] [-r <paper>] [-f <flip-detection>] [-a <auto-rotation>] <inFile.pdf> [outfile.pdf]
  7. pdfScale.sh -p
  8. pdfScale.sh -h
  9. pdfScale.sh -V
  10. Parameters:
  11. -v, --verbose
  12. Verbose mode, prints extra information
  13. Use twice for timestamp
  14. -h, --help
  15. Print this help to screen and exits
  16. -V, --version
  17. Prints version to screen and exits
  18. --install, --self-install [target-path]
  19. Install itself to [target-path] or /usr/local/bin/pdfscale if not specified
  20. Should contain the full path with the desired executable name
  21. --upgrade, --self-upgrade
  22. Upgrades itself in-place (same path/name of the pdfScale.sh caller)
  23. Downloads the master branch tarball and tries to self-upgrade
  24. --insecure, --no-check-certificate
  25. Use curl/wget without SSL library support
  26. --yes, --assume-yes
  27. Will answer yes to any prompt on install or upgrade, use with care
  28. -n, --no-overwrite
  29. Aborts execution if the output PDF file already exists
  30. By default, the output file will be overwritten
  31. Does NOT work if using --explode
  32. -m, --mode <mode>
  33. Paper size detection mode
  34. Modes: a, adaptive Default mode, tries all the methods below
  35. g, grep Forces the use of Grep method
  36. m, mdls Forces the use of MacOS Quartz mdls
  37. p, pdfinfo Forces the use of PDFInfo
  38. i, identify Forces the use of ImageMagick's Identify
  39. s, gs Forces the use of Ghostscript (PS script)
  40. -i, --info <file>
  41. Prints <file> Paper Size information to screen and exits
  42. -e, --explode
  43. Explode (split) outuput PDF into many files (one per page)
  44. --range, --page-range <page-list>
  45. Defines the page range to be processed, using the -sPageList notation
  46. Read below for more information on valid page ranges
  47. -s, --scale <factor>
  48. Changes the scaling factor or forces mixed mode
  49. Defaults: 0.95 (scale mode) / Disabled (resize mode)
  50. MUST be a number bigger than zero
  51. Eg. -s 0.8 for 80% of the original size
  52. -r, --resize <paper>
  53. Triggers the Resize Paper Mode, disables auto-scaling of 0.95
  54. Resize PDF and fit-to-page
  55. <paper> can be: source, custom or a valid std paper name, read below
  56. -c, --cropbox <paper>
  57. Resets Cropboxes on all pages to a specific paper size
  58. Only applies to resize mode
  59. <paper> can be: full | fullsize - Uses the same size as the main paper/mediabox
  60. custom - Define a custom cropbox size in inches, mm or points
  61. std paper name - Uses a paper size name (eg. a4, letter, etc)
  62. -f, --flip-detect <mode>
  63. Flip Detection Mode, defaults to 'auto'
  64. Inverts Width <-> Height of a Resized PDF
  65. Modes: a, auto Keeps source orientation, default
  66. f, force Forces flip W <-> H
  67. d, disable Disables flipping
  68. -a, --auto-rotate <mode>
  69. Setting for GS -dAutoRotatePages, defaults to 'PageByPage'
  70. Uses text-orientation detection to set Portrait/Landscape
  71. Modes: p, pagebypage Auto-rotates pages individually
  72. n, none Retains orientation of each page
  73. a, all Rotates all pages (or none) depending
  74. on a kind of "majority decision"
  75. --no-fit-to-page
  76. Disables GS option dPDFFitPage (used when resizing)
  77. --hor-align, --horizontal-alignment <left|center|right>
  78. Where to translate the scaled page
  79. Default: center
  80. Options: left, right, center
  81. --vert-align, --vertical-alignment <top|center|bottom>
  82. Where to translate the scaled page
  83. Default: center
  84. Options: top, bottom, center
  85. --xoffset, --xtrans-offset <FloatNumber>
  86. Add/Subtract from the X translation (move left-right)
  87. Default: 0.0 (zero)
  88. Options: Positive or negative floating point number
  89. --yoffset, --ytrans-offset <FloatNumber>
  90. Add/Subtract from the Y translation (move top-bottom)
  91. Default: 0.0 (zero)
  92. Options: Positive or negative floating point number
  93. --pdf-settings <gs-pdf-profile>
  94. Ghostscript PDF Profile to use in -dPDFSETTINGS
  95. Default: printer
  96. Options: screen, ebook, printer, prepress, default
  97. --print-mode <mode>
  98. Setting for GS -dPrinted, loads options for screen or printer
  99. Defaults to nothing, which uses the print profile for files
  100. The screen profile preserves URLs, but loses print annotations
  101. Modes: s, screen Use screen options > '-dPrinted=false'
  102. p, printer Use print options > '-dPrinted'
  103. --image-downsample <gs-downsample-method>
  104. Ghostscript Image Downsample Method
  105. Default: bicubic
  106. Options: subsample, average, bicubic
  107. --image-resolution <dpi>
  108. Resolution in DPI of color and grayscale images in output
  109. Default: 300
  110. --background-gray <percentage>
  111. Creates a background with a gray color setting on PDF scaling
  112. Percentage is a floating point percentage number between 0(black) and 1(white)
  113. --background-cmyk <"C M Y K">
  114. Creates a background with a CMYK color setting on PDF scaling
  115. Must be quoted into a single parameter as in "0.2 0.2 0.2 0.2"
  116. Each color parameter is a floating point percentage number (between 0 and 1)
  117. --background-rgb <"R G B">
  118. Creates a background with a RGB color setting on PDF scaling
  119. Must be quoted into a single parameter as in "100 100 200"
  120. RGB numbers are integers between 0 and 255 (255 122 50)
  121. --newpdf Uses the -dNEWPDF flag in the GS Call (deprecated in new versions of GS)
  122. --dry-run, --simulate
  123. Just simulate execution. Will not run ghostscript
  124. --print-gs-call, --gs-call
  125. Print GS call to stdout. Will print at the very end between markers
  126. -p, --print-papers
  127. Prints Standard Paper info tables to screen and exits
  128. Scaling Mode:
  129. - The default mode of operation is scaling mode with fixed paper
  130. size and scaling pre-set to 0.95
  131. - By not using the resize mode you are using scaling mode
  132. - Flip-Detection and Auto-Rotation are disabled in Scaling mode,
  133. you can use '-r source -s <scale>' to override.
  134. - Ghostscript placement is from bottom-left position. This means that
  135. a bottom-left placement has ZERO for both X and Y translations.
  136. Resize Paper Mode:
  137. - Disables the default scaling factor! (0.95)
  138. - Changes the PDF Paper Size in points. Will fit-to-page
  139. Mixed Mode:
  140. - In mixed mode both the -s option and -r option must be specified
  141. - The PDF will be first resized then scaled
  142. Page Ranges:
  143. - Please refer to the Ghostscript manual on '-sPageList' for more info and examples.
  144. - May cause execution warnings from Ghostscript if the PDF refences pages that were
  145. removed. The output file should still be created, but with broken internal links.
  146. - Using a range with an inexistant page will raise a warning from Ghostscript and
  147. may also generate blank pages.
  148. - Single page number | ex: --range 2
  149. - Interval | ex: --range 2-4
  150. - List of pages | ex: --range 1,3,6
  151. - From page to end | ex: --range 3-
  152. - odd/even specifier | ex: --range odd
  153. - odd/even range | ex: --range even:1-4
  154. - mixed entries | ex: --range 1,3-5,8-
  155. Output filename:
  156. - Having the extension .pdf on the output file name is optional,
  157. it will be added if not present.
  158. - The output filename is optional. If no file name is passed
  159. the output file will have the same name/destination of the
  160. input file with added suffixes:
  161. .SCALED.pdf is added to scaled files
  162. .<PAPERSIZE>.pdf is added to resized files
  163. .<PAPERSIZE>.SCALED.pdf is added in mixed mode
  164. Standard Paper Names: (case-insensitive)
  165. A0 A1 A2 A3 A4
  166. A4SMALL A5 A6 A7 A8
  167. A9 A10 ISOB0 ISOB1 ISOB2
  168. ISOB3 ISOB4 ISOB5 ISOB6 C0
  169. C1 C2 C3 C4 C5
  170. C6 11X17 LEDGER LEGAL LETTER
  171. LETTERSMALL ARCHE ARCHD ARCHC ARCHB
  172. ARCHA JISB0 JISB1 JISB2 JISB3
  173. JISB4 JISB5 JISB6 FLSA FLSE
  174. HALFLETTER HAGAKI
  175. Custom Paper Size:
  176. - Paper size can be set manually in Millimeters, Inches or Points
  177. - Custom paper definition MUST be quoted into a single parameter
  178. - Actual size is applied in points (mms and inches are transformed)
  179. - Measurements: mm, mms, millimeters
  180. pt, pts, points
  181. in, inch, inches
  182. Use: pdfScale.sh -r 'custom <measurement> <width> <height>'
  183. Ex: pdfScale.sh -r 'custom mm 300 300'
  184. Using Source Paper Size: (no-resizing)
  185. - Wildcard 'source' is used to keep paper size the same as the input
  186. - Useful to run Auto-Rotation without resizing
  187. - Eg. pdfScale.sh -r source ./input.pdf
  188. Backgrounding: (paint a background)
  189. - Backgrounding only happens when scaling
  190. - Use a scale of 1.0 to force mixed mode and add background while resizing
  191. Options and Parameters Parsing:
  192. - From v2.1.0 (long-opts) there is no need to pass file names at the end
  193. - Anything that is not a short-option is case-insensitive
  194. - Short-options: case-sensitive Eg. -v for Verbose, -V for Version
  195. - Long-options: case-insensitive Eg. --SCALE and --scale are the same
  196. - Subparameters: case-insensitive Eg. -m PdFinFo is valid
  197. - Grouping short-options is not supported Eg. -vv, or -vs 0.9
  198. Additional Notes:
  199. - File and folder names with spaces should be quoted or escaped
  200. - Using a scale bigger than 1.0 may result on cropping parts of the PDF
  201. - For detailed paper types information, use: pdfScale.sh -p
  202. Examples:
  203. pdfScale.sh myPdfFile.pdf
  204. pdfScale.sh -i '/home/My Folder/My PDF File.pdf'
  205. pdfScale.sh myPdfFile.pdf "My Scaled Pdf"
  206. pdfScale.sh -v -v myPdfFile.pdf
  207. pdfScale.sh -s 0.85 myPdfFile.pdf My\ Scaled\ Pdf.pdf
  208. pdfScale.sh -m pdfinfo -s 0.80 -v myPdfFile.pdf
  209. pdfScale.sh -v -v -m i -s 0.7 myPdfFile.pdf
  210. pdfScale.sh -r A4 myPdfFile.pdf
  211. pdfScale.sh -v -v -r "custom mm 252 356" -s 0.9 -f "../input file.pdf" "../my new pdf"

Standard Paper Tables

The -p parameter prints detailed paper types information

  1. $ pdfscale -p
  2. pdfscale v2.3.7
  3. Paper Sizes Information
  4. +-----------------------------------------------------------------+
  5. | ISO STANDARD |
  6. +-----------------------------------------------------------------+
  7. | Name | inchW | inchH | mm W | mm H | pts W | pts H |
  8. +-----------------+-------+-------+-------+-------+-------+-------+
  9. | a0 | 33.1 | 46.8 | 841 | 1189 | 2384 | 3370 |
  10. | a1 | 23.4 | 33.1 | 594 | 841 | 1684 | 2384 |
  11. | a2 | 16.5 | 23.4 | 420 | 594 | 1191 | 1684 |
  12. | a3 | 11.7 | 16.5 | 297 | 420 | 842 | 1191 |
  13. | a4 | 8.3 | 11.7 | 210 | 297 | 595 | 842 |
  14. | a4small | 8.3 | 11.7 | 210 | 297 | 595 | 842 |
  15. | a5 | 5.8 | 8.3 | 148 | 210 | 420 | 595 |
  16. | a6 | 4.1 | 5.8 | 105 | 148 | 297 | 420 |
  17. | a7 | 2.9 | 4.1 | 74 | 105 | 210 | 297 |
  18. | a8 | 2.1 | 2.9 | 52 | 74 | 148 | 210 |
  19. | a9 | 1.5 | 2.1 | 37 | 52 | 105 | 148 |
  20. | a10 | 1.0 | 1.5 | 26 | 37 | 73 | 105 |
  21. | isob0 | 39.4 | 55.7 | 1000 | 1414 | 2835 | 4008 |
  22. | isob1 | 27.8 | 39.4 | 707 | 1000 | 2004 | 2835 |
  23. | isob2 | 19.7 | 27.8 | 500 | 707 | 1417 | 2004 |
  24. | isob3 | 13.9 | 19.7 | 353 | 500 | 1001 | 1417 |
  25. | isob4 | 9.8 | 13.9 | 250 | 353 | 709 | 1001 |
  26. | isob5 | 6.9 | 9.8 | 176 | 250 | 499 | 709 |
  27. | isob6 | 4.9 | 6.9 | 125 | 176 | 354 | 499 |
  28. | c0 | 36.1 | 51.1 | 917 | 1297 | 2599 | 3677 |
  29. | c1 | 25.5 | 36.1 | 648 | 917 | 1837 | 2599 |
  30. | c2 | 18.0 | 25.5 | 458 | 648 | 1298 | 1837 |
  31. | c3 | 12.8 | 18.0 | 324 | 458 | 918 | 1298 |
  32. | c4 | 9.0 | 12.8 | 229 | 324 | 649 | 918 |
  33. | c5 | 6.4 | 9.0 | 162 | 229 | 459 | 649 |
  34. | c6 | 4.5 | 6.4 | 114 | 162 | 323 | 459 |
  35. +-----------------+-------+-------+-------+-------+-------+-------+
  36. +-----------------------------------------------------------------+
  37. | US STANDARD |
  38. +-----------------------------------------------------------------+
  39. | Name | inchW | inchH | mm W | mm H | pts W | pts H |
  40. +-----------------+-------+-------+-------+-------+-------+-------+
  41. | 11x17 | 11.0 | 17.0 | 279 | 432 | 792 | 1224 |
  42. | ledger | 17.0 | 11.0 | 432 | 279 | 1224 | 792 |
  43. | legal | 8.5 | 14.0 | 216 | 356 | 612 | 1008 |
  44. | letter | 8.5 | 11.0 | 216 | 279 | 612 | 792 |
  45. | lettersmall | 8.5 | 11.0 | 216 | 279 | 612 | 792 |
  46. | archE | 36.0 | 48.0 | 914 | 1219 | 2592 | 3456 |
  47. | archD | 24.0 | 36.0 | 610 | 914 | 1728 | 2592 |
  48. | archC | 18.0 | 24.0 | 457 | 610 | 1296 | 1728 |
  49. | archB | 12.0 | 18.0 | 305 | 457 | 864 | 1296 |
  50. | archA | 9.0 | 12.0 | 229 | 305 | 648 | 864 |
  51. +-----------------+-------+-------+-------+-------+-------+-------+
  52. +-----------------------------------------------------------------+
  53. | JIS STANDARD *Aproximated Points |
  54. +-----------------------------------------------------------------+
  55. | Name | inchW | inchH | mm W | mm H | pts W | pts H |
  56. +-----------------+-------+-------+-------+-------+-------+-------+
  57. | jisb0 | NA | NA | 1030 | 1456 | 2920 | 4127 |
  58. | jisb1 | NA | NA | 728 | 1030 | 2064 | 2920 |
  59. | jisb2 | NA | NA | 515 | 728 | 1460 | 2064 |
  60. | jisb3 | NA | NA | 364 | 515 | 1032 | 1460 |
  61. | jisb4 | NA | NA | 257 | 364 | 729 | 1032 |
  62. | jisb5 | NA | NA | 182 | 257 | 516 | 729 |
  63. | jisb6 | NA | NA | 128 | 182 | 363 | 516 |
  64. +-----------------+-------+-------+-------+-------+-------+-------+
  65. +-----------------------------------------------------------------+
  66. | OTHERS |
  67. +-----------------------------------------------------------------+
  68. | Name | inchW | inchH | mm W | mm H | pts W | pts H |
  69. +-----------------+-------+-------+-------+-------+-------+-------+
  70. | flsa | 8.5 | 13.0 | 216 | 330 | 612 | 936 |
  71. | flse | 8.5 | 13.0 | 216 | 330 | 612 | 936 |
  72. | halfletter | 5.5 | 8.5 | 140 | 216 | 396 | 612 |
  73. | hagaki | 3.9 | 5.8 | 100 | 148 | 283 | 420 |
  74. +-----------------+-------+-------+-------+-------+-------+-------+

Dependencies

The script uses basename, grep, bc and gs (ghostscript).
You probably have everything installed already, except for ghostscript.
Optional dependencies are imagemagick, pdfinfo and mdls (Mac).
This app is focused in Bash, so it will probably not run in other shells.
The script will need to see the dependencies on your $PATH variable.

apt-get
  1. sudo apt-get install ghostscript bc
yum
  1. sudo yum install ghostscript bc
homebrew MacOS
  1. brew install ghostscript
Optionals

Page Size detection is by default in Adaptive Mode.
It will try the following methods in sequence:

  1. Try to get /MediaBox with grep (fastest)
  2. Failed AND MacOS ? Try mdls
  3. Failed ? Try pdfinfo
  4. Failed ? Try ImageMagick’s identify
  5. Failed ? Try Ghostscript with a PS script
  6. Failed ? Exit with error message

The grep method will fail on PDFs without a /MediaBox.
You may install any of the optionals to be used in that case.

MacOS is fine using mdls if the metadata of the file is accurate.
The metadata is generated automatically by the OS (Spotlight)

apt-get
  1. sudo apt-get install imagemagick pdfinfo
yum
  1. sudo yum install imagemagick pdfinfo
homebrew MacOS
  1. brew install imagemagick xpdf

Windows

  • The script should work fine in cygwin.
  • If you are using msys/git for windows, and the script exits with a ‘file not found’ error,
  • try running export MSYS_NO_PATHCONV=1
  • and export MSYS2_ARG_CONV_EXCL="*"
  • and then running again.

Clone using git

  1. git clone https://github.com/tavinus/pdfScale.git
  2. cd ./pdfScale
  3. ./pdfScale.sh --version

Self-Install

Since v2.3.0 pdfScale can install itself using the parameter --install.

By default it will install to /usr/local/bin/pdfscale

  1. ./pdfScale.sh --install

A custom location can be specified as a parameter.
Should contain full path to executable file.

  1. ./pdfScale.sh --install /opt/pdfscale/pdfscale

Run installer using curl or wget

wget oneliners

  1. # Normal install with prompts
  2. wget -q -O /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/master/pdfScale.sh' && bash /tmp/pdfScale.sh --install
  3. # Automated install with --assume-yes
  4. wget -q -O /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/master/pdfScale.sh' && bash /tmp/pdfScale.sh --install --assume-yes
  5. # To ignore SSL, use --no-check-certificate
  6. wget --no-check-certificate -q -O /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/master/pdfScale.sh' && bash /tmp/pdfScale.sh --install

curl oneliners

  1. # Normal install with prompts
  2. curl -s -o /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/master/pdfScale.sh' && bash /tmp/pdfScale.sh --install
  3. # Automated install with --assume-yes
  4. curl -s -o /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/master/pdfScale.sh' && bash /tmp/pdfScale.sh --install --assume-yes
  5. # To ignore SSL, use --insecure
  6. curl --insecure -s -o /tmp/pdfScale.sh 'https://raw.githubusercontent.com/tavinus/pdfScale/master/pdfScale.sh' && bash /tmp/pdfScale.sh --install

Remove /tmp/pdfScale.sh after done

  1. rm /tmp/pdfScale.sh

Install with make

The make installer will name the executable as pdfscale with no uppercase chars and without the .sh extension.

If you have make installed you can use it to install to /usr/local/bin/pdfscale with:

  1. sudo make install

To remove the installation use:

  1. sudo make uninstall

Self-Upgrade

Since v2.3.0 pdfScale can upgrade itself using the parameter --upgrade.

It will try to get the master branch and update itself in-place.

  1. pdfscale --upgrade

More info on the Self-Upgrade Wiki


Links

ma.juii.net - The History

SO - Scale pdf to add border for printing full size pages

MichaelJCole original gist - pdfScale.sh