How do I reduce a PDF's size and preserve the bookmarks?
Solution 1:
You can try ghostscript with ebook output and the bookmarks seems to be preserved:
gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dPDFSETTINGS=/ebook -sOutputFile=newFile.pdf originalFile.pdf
Solution 2:
@Vishnu Kumar
I'm glad you asked. Your question led me to re-examine this issue and I found out that I had extracted 100 pages from a 1000+ page PDF, using Acrobat Pro, as a test case, however that did not include the TOC bookmarks as I had assumed and that was the problem. So I opened the original large PDF in Acrobat Pro and deleted all but the first 100 pages and deleted all but the relevant bookmarks and saved that as my test case. Now the TOC is being preserved.
Here is my comparison of the two settings:
/ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -dNOPAUSE -dBATCH -sOutputFile=reduced/output_1-102_TOC_[gs-ebook].pdf input_1-102_TOC.pdf
ridiculously slow
91.7MB-->33.4MB (36% of original)
TOC preserved
quality poor - pixellated
/printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/printer -dNOPAUSE -dBATCH -sOutputFile=reduced/output_1-102_TOC_[gs-printer].pdf input_1-102_TOC.pdf
fast
91.7MB-->68.9MB (75% of original)
TOC preserved
quality almost identical
Other settings:
/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/default -dNOPAUSE -dBATCH -sOutputFile=reduced/output_1-102_TOC_[gs-default].pdf input_1-102_TOC.pdf
fast
91.7MB-->60.8MB (66% of original)
TOC preserved
quality almost identical
/prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
gs -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -dNOPAUSE -dBATCH -sOutputFile=reduced/output_1-102_TOC_[gs-prepress].pdf input_1-102_TOC.pdf
fast
91.7MB-->80.2MB (87% of original)
TOC preserved
quality almost identical
As can be seen, the /default
setting performed best, giving the smallest size for the best qualiy.