dealfonso / sapp

Simple and Agnostic PDF Document Parser in PHP - sign PDF docs using PHP
GNU Lesser General Public License v3.0
115 stars 30 forks source link

Error on read some PDFs #7

Closed gucosta90 closed 1 year ago

gucosta90 commented 3 years ago

Hello Carlos!

First, congratulations for the project, very easy to use!

However, I am having a problem reading some PDFs. Most of them get the error "failed to parse file"

One of the examples follows attaching : CAPÍTULO 22.pdf

dealfonso commented 3 years ago

Hi,

the problem is the same than in issue #3

At this time, sapp is not able to deal with non-0 generation PDF objects. I hope to provide support for them soon.

Sorry.

gucosta90 commented 3 years ago

Thank you.

I found a temporary solution for this case, maybe can help others people or increment sapp:

Solution: on case error, convert the PDF with Ghostscript (https://www.ghostscript.com/). I'm using the command below: exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile="'. $pdf_new.'" "'.$pdf_old.'" 2>&1');

Ghostscript must be installed on Linux, of course. Case Windows, use this command: shell_exec('"c:\Program Files\gs\gs9.54.0\bin\gswin64c" -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sOutputFile="'. $pdf_new.'" "'.$pdf_old.'" 2>&1');

dealfonso commented 3 years ago

Hi,

Sorry but my advice is to not to use this method: when you transform the pdf using ghostscript you are modifying the original doc and its structure. So you cannot keep some features of the original doc. e.g. keep previous signatures. At the end, you are not signing the original document.

I'd wait for the support for non-zero generation objects to use this kind of documents.

dealfonso commented 1 year ago

Hi,

the latest comit adds basic support for non-zero generation and solves this issue. So you can now open your document.

@gucosta90 could you please check it?

dealfonso commented 1 year ago

closing because there is no activity, and seems to be solved.