pts / pdfsizeopt

PDF file size optimizer
GNU General Public License v2.0
764 stars 66 forks source link

PDF Sign error #94

Closed JhonGH closed 6 years ago

JhonGH commented 6 years ago

Hi, I am facing with an error during the sign process of a reduced pdf. After reducing its size with pdfsizeopt latest release, I need to digitally sign the file, but the following error appears:

exception in thread "main" java.lang.NullPointerException' at com.lowagie.text.pdf.PdfReader.readPages(Unknown Source) at com.lowagie.text.pdf.PdfReader.readPdf(Unknown Source) at com.lowagie.text.pdf.PdfReader.<init>(Unknown Source)

I tried some flags (e.g. --do-optimize-obj-heads) with no success. To sign I am using a java library with a modified version of iText 1.4. The pdf file that I have problem with is about 7500 pages and 200MB.

A tip: Using Acrobat Reader, after opening and saving the compressed pdf, I can correctly sign the file.

Can it be a bug that you can try to fix with a new release? Thanks J

pts commented 6 years ago

Thank you for reporting this!

This is most probably a bug in the Java library you are using. Even if the PDF created by pdfsizeopt is broken, the Java library should report a meaningful error message rather than java.lang.NullPointerException. You may want to report this bug to the authors of the Java library.

You may want to try signing a smaller PDF, e.g. only page 1 of the original, and see if it succeeds or not. Report the bug with the smallest possible PDF which fails.

It's nice that Acrobat Reader is able to fix the PDF created by pdfsizeopt for you. I understand that it would be nicer that pdfsizeopt had a command-line flag which would cause the creation of a PDF which doesn't need fixing. To get this, we need to investigate and understand which feature of the PDF makes your Java library fail. (I can do this, but I'll quote my regular hourly rate for this work. You have to provide the input PDF file, the .jar file of your Java library and the command line with which you do the signing. Find my e-mail address in the git log if you are interested in this. Please don't attach files to the e-mail.) After understanding it, I can easily add the flag to pdfsizeopt (for free).

I'm closing this issue now. I'll reopen it as soon as someone adds the missing info (which feature of the PDF makes your java library fail) as a comment.

JhonGH commented 6 years ago

Thank you very much for the answer! I tried with a smaller pdf file with only one page, and it worked. Now, I'm trying with some other tool, that I find around, to fix the pdf after the reducing process.... And I want to check if the original pdf has a problem inside.

J

pts commented 6 years ago

You may want to do a bisection on the pages of your large compressed PDF: i.e. try the first half (7500/2 pages). If that works, try the second half. Always focus on the one half which breaks, and make it smaller.