abarker / pdfCropMargins

pdfCropMargins -- a program to crop the margins of PDF files
Other
357 stars 34 forks source link

links affected #40

Closed naisman closed 1 year ago

naisman commented 2 years ago

well working in cropping margins, like a charm, thanks a lot. and regretfully find links in the cropped pdf not working in some readers, ie. foxit (win10) and pdfexpert (ios) after optimizing the cropped pdf by acrobat, things get worse, all links not working even in adobe reader. Bookmarks works well after cropping.

naisman commented 2 years ago

I tried the below swiches, all the same in the end. -c p: Force the use of pdftoppm rendering. -c gr: Force the use of Ghostscript rendering (equivalent to --gsRender).

abarker commented 2 years ago

The rendering methods are only used to render pages so that they can be analyzed to find the margins. All the changes in the final PDF are performed using PyPDF2. In particular, the box metadata such as the CropBox and MediaBox may be modified, as well as the ArtBox and Producer metadata if the restore option is enabled (the latter can be disabled with the --noundosave option).

The metadata is explicitly copied over using PyPDF2 calls, since PyPDF2 does not do that automatically. I haven't looked into the link metadata.

The issue may be related to this PyPDF2 issue: https://github.com/py-pdf/PyPDF2/issues/471

leonhd commented 2 years ago

It looks like bookmarks and links in book's "table of contents" are also affected. The bookmarks work when the cropped pdf file is opened in acrobat reader; but it does not work when opened in other reader, for example, the default pdf reader in ubuntu 20.

litianqi commented 1 year ago

For anyone inerested, TOC can be fixed by HandyOutliner. Run OutlineTool.exe -s:"source.pdf" -t:"target.pdf" to copy TOC from source.pdf to target.pdf.

darksimpson commented 1 year ago

It looks like TOC and bookmarks cloning things was fixed in PyPDF version 3+. Do you think about moving to latest PyPDF?

abarker commented 1 year ago

@darksimpson, the current version of PyPDF is set to <3.0 because newer versions seem to have changed or broken something that causes pdfCropMargins to improperly calculate margins (see issue https://github.com/abarker/pdfCropMargins/issues/45). I haven't had time to look into that problem, or make the other changes for the newer versions of PyPDF2 (which was also renamed to simply PyPDF in recent versions).

GuoXu-GX commented 1 year ago

For anyone inerested, TOC can be fixed by HandyOutliner. Run OutlineTool.exe -s:"source.pdf" -t:"target.pdf" to copy TOC from source.pdf to target.pdf.

I have a try, it looks like this tool does not work. I copy the TOC from a verified pdf file to the cropped version of the same document, move the new document to my ebook reader, it still does not work.

abarker commented 1 year ago

Try the new version 2.0.0. It removes the PyPDF dependency and uses PyMuPDF for all internal calculations.

GuoXu-GX commented 1 year ago

Try the new version 2.0.0. It removes the PyPDF dependency and uses PyMuPDF for all internal calculations.

aha, I have a try, and it really works; the newly cropped document works as expected. Thank you very much!