Nástroje používateľa

Nástoje správy stránok


blog:odborny:2025-05-07-command-line_tools_for_pdf_processing

Rozdiely

Tu môžete vidieť rozdiely medzi vybranou verziou a aktuálnou verziou danej stránky.

Odkaz na tento prehľad zmien

Obojstranná predošlá revíziaPredchádzajúca revízia
Nasledujúca revízia
Predchádzajúca revízia
blog:odborny:2025-05-07-command-line_tools_for_pdf_processing [2026/04/30 10:56] – [1. Minimize PDF size] Róbert Tothblog:odborny:2025-05-07-command-line_tools_for_pdf_processing [2026/05/15 13:10] (aktuálne) Róbert Toth
Riadok 120: Riadok 120:
   ; <color blue>Transparency</color> tab      : 🚫 This causes optimisation to take extremely long time in some PDFs. My default is to have it turned off (and I cannot remember a situation when I actually needed to turn it on).   ; <color blue>Transparency</color> tab      : 🚫 This causes optimisation to take extremely long time in some PDFs. My default is to have it turned off (and I cannot remember a situation when I actually needed to turn it on).
   ; <color blue>Discard Objects</color> tab   : ✅ Everything on, except **Discard bookmarks** (you never want that) and also **Convert smooth lines to curves** and **Detect and merge image fragments** (these are not needed in 99% of cases and they cause optimisation to take significantly longer, while they usually do not lower the PDF size at all). You might also want to **Discard all Javascript actions**, but if there are any internal links (e.g. table of contents, references or index pointing to specific places in PDF), this causes them to disfunction.   ; <color blue>Discard Objects</color> tab   : ✅ Everything on, except **Discard bookmarks** (you never want that) and also **Convert smooth lines to curves** and **Detect and merge image fragments** (these are not needed in 99% of cases and they cause optimisation to take significantly longer, while they usually do not lower the PDF size at all). You might also want to **Discard all Javascript actions**, but if there are any internal links (e.g. table of contents, references or index pointing to specific places in PDF), this causes them to disfunction.
-  ; <color blue>Discard User Data</color> tab : ✅ Everything on.+  ; <color blue>Discard User Data</color> tab : ✅ Everything on. Note, however, that if you have any internal cross-references (e.g. clickable links from Contents page to specific parts of the document) in the PDF, you have to turn off **Discard all comments, forms and multimedia**, since this will also remove all these links.
   ; <color blue>Clean Up</color> tab          : ✅ Everything on.   ; <color blue>Clean Up</color> tab          : ✅ Everything on.
 +
 +=== ❗️"Save as optimized PDF" in Acrobat breaks hyperlinks (internal cross-references)❗️ ===
 +This is just an addition to a note above under //<color blue>Discard User Data</color> tab//. I want to repeat it because it can seriously break your workflow and it is completely undocumented (and unexpected).
 +
 +Having **Discard all comments, forms and multimedia** (under **Discard User Data** tab) turned on while optimising PDF in Adobe Acrobat will also remove all internal cross-references (e.g. clickable links from Contents page to specific parts of the document). This was spotted [[https://graphicdesign.stackexchange.com/questions/68389/save-as-optimized-pdf-in-acrobat-breaks-hyperlinks-created-in-indesign|here on GraphicDesign stack exchange]].
  
  
Riadok 290: Riadok 295:
  
 QPDF currently [[https://github.com/qpdf/qpdf/issues/339|does not support]] maintaining the original object ID. QPDF currently [[https://github.com/qpdf/qpdf/issues/339|does not support]] maintaining the original object ID.
 +
 +
 +===== - Resetting PDF page coordinates (remove CropBox/MediaBox shift) =====
 +**Example use-case:** you have a PDF with pages consisting of scanned images, which are cropped accordingly so that each page is the same size and the real scanned page is situated properly inside the PDF page. You want to OCR these pages (using Adobe Acrobat's OCR to "Editable text & images"). However, while doing OCR, Acrobat also resets all the page coordinates to (0,0), which causes some other page elements (e.g. annotations, internal hyperlinks etc.) to become improperly shifted away. So the solution in this case is to manually reset these coordinates in the original PDF before trying to OCR it.
 +
 +==== TL;DR: Summary first ====
 +<color blue/lightgrey>**Conclusion:** Use Coherent PDF's ''-upright'' method below. No other tool is capable of doing this.</color>
 +
 +==== Coherent PDF (cpdf) ====
 +Although listed under "Rotating Pages" section, the [[https://www.coherentpdf.com/cpdfmanual/cpdfmanualch3.html#x6-560003.4|cpdf -upright]] method also "makes sure the media box has its origin at (0,0), changing other boxes to compensate" – which is exactly what we wanted! And it is //this// easy:
 +<code>
 +cpdf -upright "in.pdf" -o "out.pdf"
 +</code>
 +
 +
 +===== - Make Adobe Acrobat appear in "Open with" menu for images =====
 +  * **Example use-case #1:** You want to create PDF from image //quickly//. When you open an image in Adobe Acrobat, it automatically converts it to PDF file. This //would be// perfect, if Acrobat actually allowed you to open image files directly.
 +  * **Example use-case #2:** You have a series of scanned pages which you want to combine into a PDF. When you open several images with Acrobat, it will automatically ask you whether you want to combine them into single PDF file. Again, this would be perfect, if you were allowed to open those images in Acrobat…
 +
 +Adobe Acrobat is perfectly capable of opening common image types (e.g. ''*.jpg'', ''*.png'' or ''*.tiff'' files) and in this case, it automatically converts them to PDF file. Yet, it does not register itself as an app for opening those files. This means that you must:
 +  * either manually locate the ''Adobe Acrobat.app'' through ''Open with → Other…'' command each time you want to open an image in Acrobat,
 +  * //or// you can open the image from Acrobat, but in this case you must click the ''Options'' button in Open menu and select ''All files'' under ''Show:'' menu – otherwise you won't be able to select image files in the Open menu (they will be greyed-out). Again, you have to do this every single time you want to open an image in Acrobat.
 +
 +==== Solution: Manually adding images as Acrobat-recognized file types ====
 +  - Locate ''info.plist'' file under ''Adobe Acrobat.app → Contents''
 +  - Make a backup copy of the file (this will ask for a password, since Acrobat installs itself with extra permissions).
 +  - Open ''info.plist'' file with editor and locate a ''<nowiki><key>CFBundleDocumentTypes</key></nowiki>'' line.
 +  - Add the following lines to the beginning of the ''<array>'' section – like this:<WRAP prewrap><code xml>
 +<key>CFBundleDocumentTypes</key>
 +<array>
 + <!-- FurloSK BEGIN: added jpg, tiff, png extensions -->
 + <!-- after changing, run this command to refresh system associations:
 + /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "/Applications/Adobe Acrobat DC/Adobe Acrobat.app/"
 + -->
 + <dict>
 + <key>CFBundleTypeName</key>
 + <string>JPEG Image</string>
 + <key>CFBundleTypeRole</key>
 + <string>Viewer</string>
 + <key>LSHandlerRank</key>
 + <string>Alternate</string>
 + <key>LSItemContentTypes</key>
 + <array>
 + <string>public.jpeg</string>
 + </array>
 + </dict>
 + <dict>
 + <key>CFBundleTypeName</key>
 + <string>Portable Network Graphics Image</string>
 + <key>CFBundleTypeRole</key>
 + <string>Viewer</string>
 + <key>LSHandlerRank</key>
 + <string>Alternate</string>
 + <key>LSItemContentTypes</key>
 + <array>
 + <string>public.png</string>
 + </array>
 + </dict>
 + <dict>
 + <key>CFBundleTypeName</key>
 + <string>TIFF Image</string>
 + <key>CFBundleTypeRole</key>
 + <string>Viewer</string>
 + <key>LSHandlerRank</key>
 + <string>Alternate</string>
 + <key>LSItemContentTypes</key>
 + <array>
 + <string>public.tiff</string>
 + </array>
 + </dict>
 + <!-- FurloSK END: added jpg, tiff, png extensions -->
 + <!-- … continuing with the default Document Types -->
 + <dict>
 + <key>CFBundleTypeExtensions</key>
 + <array>
 + <string>acrobatsecuritysettings</string>
 + </array>
 +
 +</code></WRAP>
 +  - After this, force macOS to refresh file types associations from Acrobat by running:<WRAP prewrap><code>
 +/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f "/Applications/Adobe Acrobat DC/Adobe Acrobat.app/"
 +</code></WRAP>
 +  - Done! ''Open with'' menu should now list Adobe Acrobat for ''*.jpg'', ''*.png'' or ''*.tiff'' file types.
 +
 +=== Possible code-signing issue ("Signature not valid" warning) ===
 +This is not happening specifically with Acrobat, but generally speaking, when you change an app's ''Info.plist'' file (or, for that matter, any other resource inside the App bundle) and that app is signed, its _CodeSignature will no longer be valid and you might be unable to re-run the app. In that case, you need to force app re-signing with this command: <code>codesign --force --deep --sign - /Applications/Adobe Acrobat DC/Adobe Acrobat.app</code>
 +
 +Original source: [[https://www.reddit.com/r/MacOS/comments/1ddq9lf/comment/l8841yp/|Reddit]]
 +
  
  
Riadok 338: Riadok 432:
 ~~socialite~~ ~~socialite~~
 {{tag>pdf}} {{tag>pdf}}
 +  ; Page visits : ~~QUICKSTATS:total~~ 
 +  ; total : {{counter|total}} 
 +  ; today : {{counter|today}}
  
 ===== Comments ===== ===== Comments =====
blog/odborny/2025-05-07-command-line_tools_for_pdf_processing.1777539393.txt.gz · Posledná úprava: 2026/04/30 10:56 od Róbert Toth