Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bookmarking a PDF also shrinks its file size and compresses images #3

Open
madamadami opened this issue Apr 21, 2021 · 1 comment
Open

Comments

@madamadami
Copy link

I like your script and used it quite a lot recently. Unfortunately, the PDFs get compressed pretty much and so images lose a lot of quality. How can I avoid recompression?

@smfukaya
Copy link

smfukaya commented Jul 29, 2022

@madamadami, perhaps you could add the Ghostscript settings (highlighted in bold) posted Kurt Pfeifle is his answer to Use Ghostscript, but tell it to not reprocess images?.

So the complete Ghostscript commandline that could make you happy should read:

gs
-o book.pdf
-sDEVICE=pdfwrite
-dColorConversionStrategy=/LeaveColorUnchanged
-dDownsampleMonoImages=false
-dDownsampleGrayImages=false
-dDownsampleColorImages=false
-dAutoFilterColorImages=false
-dAutoFilterGrayImages=false
-dColorImageFilter=/FlateEncode
-dGrayImageFilter=/FlateEncode
title.pdf
content.pdf

Find where your pdf-bookmark was installed with the following command:
pip show pdf-bookmark

Name: pdf-bookmark
Version: 1.1.0
Summary: PDF Bookmark Import and Export
Home-page: https://github.com/xianghuzhao/pdf-bookmark
Author: Xianghu Zhao
Author-email: xianghuzhao@gmail.com
License: MIT
Location: c:\LOCATION\python\python310\lib\site-packages
Requires:
Required-by:

Edit the "c:\LOCATION\python\python310\lib\site-packages\pdf-bookmark.py" (change the path accordingly) file, find the call command to ghostscript executable, add the above settings to the arguments array and save the file.

    call(['gs', '-dBATCH', '-dNOPAUSE', '-sDEVICE=pdfwrite',
          '-dColorConversionStrategy=/LeaveColorUnchanged', '-dDownsampleMonoImages=false', '-dDownsampleGrayImages=false', '-dDownsampleColorImages=false',
          '-dAutoFilterColorImages=false', '-dAutoFilterGrayImages=false', '-dColorImageFilter=/FlateEncode', '-dGrayImageFilter=/FlateEncode',
          '-sOutputFile={}'.format(output_pdf),
          pdfmark_noop,
          pdf,
          pdfmark_restore,
          pdfmark_file,
          pdfmark_pagemode])

Run the pdf-bookmark and check if the image quality suits your need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants