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

Issues with Examples #12

Closed JMHAVANCE closed 2 years ago

JMHAVANCE commented 2 years ago

PS C:\xampp\htdocs\signer\sapp> php pdfrebuild.php examples/testdoc.pdf > testdoc-rebuilt.pdf

PHP Fatal error:  Uncaught Exception: Invalid token: pos: 50143, c:  , n: \, t: \000, tt: simple, b: \000Q\000u\000a\000r\000t\000z\000 \000P\000D\000F
 in C:\xampp\htdocs\signer\sapp\src\PDFObjectParser.php:351
Stack trace:
#0 C:\xampp\htdocs\signer\sapp\src\PDFObjectParser.php(391): ddn\sapp\PDFObjectParser->_parse_obj()
#1 C:\xampp\htdocs\signer\sapp\src\PDFObjectParser.php(150): ddn\sapp\PDFObjectParser->_parse_value()
#2 C:\xampp\htdocs\signer\sapp\src\PDFUtilFnc.php(631): ddn\sapp\PDFObjectParser->parse(Object(ddn\sapp\helpers\StreamReader))
#3 C:\xampp\htdocs\signer\sapp\src\PDFUtilFnc.php(484): ddn\sapp\PDFUtilFnc::object_from_string('%PDF-1.3\n%\xC4\xE5\xF2\xE5\xEB...', 1, 49883, NULL)
#4 C:\xampp\htdocs\signer\sapp\src\PDFUtilFnc.php(542): ddn\sapp\PDFUtilFnc::find_object_at_pos('%PDF-1.3\n%\xC4\xE5\xF2\xE5\xEB...', 1, 49875, Array)
#5 C:\xampp\htdocs\signer\sapp\src\PDFDoc.php(246): ddn\sapp\PDFUtilFnc::find_object('%PDF-1.3\n%\xC4\xE5\xF2\xE5\xEB...', Array, 1)
#6 C:\xampp\htdocs\signer\sapp\src\PDFDoc.php(555): ddn\sapp\PDFDoc->get_object(1)
#7 C:\xampp\htdocs\signer\sapp\src\PDFDoc.php(675): ddn\sapp\PDFDoc->update_mod_date()
#8 C:\xampp\htdocs\signer\sapp\src\PDFDoc.php(812): ddn\sapp\PDFDoc->to_pdf_file_b(true)
#9 C:\xampp\htdocs\signer\sapp\pdfrebuild.php(37): ddn\sapp\PDFDoc->to_pdf_file_s(true)
#10 {main}
  thrown in C:\xampp\htdocs\signer\sapp\src\PDFObjectParser.php on line 351

I am using windows with a fresh install using these instructions:

$ git clone https://github.com/dealfonso/sapp
$ cd sapp
$ composer dump-autoload
$ php pdfrebuild.php examples/testdoc.pdf > testdoc-rebuilt.pdf
dealfonso commented 2 years ago

Hi,

sorry, the last commit had an error... I have reverted it. Now it is working.

JMHAVANCE commented 2 years ago

Thank you for the quick reply!

I've pulled the latest commit but I am still having issues:

> cat .\.git\refs\heads\main
4c92b5f119d730c0dc6d3729c7efbbb04b2dc749
> php pdfrebuild.php examples/testdoc.pdf > testdoc-rebuilt.pdf
Debug info at C:\xampp\htdocs\signer\sapp\src\PDFDoc.php:755: generating xref using classic xref...trailer

A PDF is generated, but when opening in Adobe I get this message:

Adobe Acrobat Reader could no open 'testdoc-rebuilt.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).

This happens when trying to sign the documents as well.

dealfonso commented 2 years ago

Hi,

that is a problem that has to do with pipes in Windows. In Linux and MacOS, it works as expected. If you write the result to a file instead of using pipes, it works as expected.

To show how to do it, I have modified the example pdfrebuild.php to accept an extra parameter to write to a file.

JMHAVANCE commented 2 years ago

You're The Man Now, Dog. =]

(Thank you!!)