Print Page | Close Window

SaveToFile with signature

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=3054
Printed Date: 29 Apr 24 at 12:41PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: SaveToFile with signature
Posted By: John Chen
Subject: SaveToFile with signature
Date Posted: 21 Jan 15 at 3:31AM
Used QP.LoadFromFile(L"xxx.pdf",L"") to open pdf file with signature. Then used QP.SaveToFile(L"yyy.pdf") to save to different pdf file. The signature become "Signature contains incorrect....". How can I save as  a pdf file with signature to different pdf file? 



Replies:
Posted By: mLipok
Date Posted: 23 Jan 15 at 4:05AM
If you change anything in any (not only PDF) signed file then signature always will show you similar message.
In another case, the signatures would be useless.


-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: John Chen
Date Posted: 23 Jan 15 at 6:59AM
I didn't change any thing, just LoadFromFile then SaveToFile. The signature shown "Error...". I used the Adobe reader to open same file, then "SaveAs" to other file, the signature seem fine. 


Posted By: mLipok
Date Posted: 25 Jan 15 at 1:14PM
When using Acrobat Reader, the option Save As,  just make a copy of the same file (compare the contents in an editor HEX).

When you open a PDF document using library functions QP.LoadFromFile then using QP.SaveToFile, you do not create a copy of this document. You create a new (different) document (compare the contents in an editor HEX).

Because the contents of the file is changed, the message "Signature contains incorrect ...." is clear and correct.


-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: John Chen
Date Posted: 26 Jan 15 at 10:05AM
Thank you,mLipok.

I have a new question about signature. I have 3 way to try for signature.
The B.pdf file with signature1, then add new signature2 and save to c.pdf
(1). 
nSignProcessID =QP.NewSignProcessFromFile(L"C:\\TEST\\B.pdf",L"");
............................
QP.EndSignProcessToFile(nSignProcessID,L"c:\\test\\C.pdf");   
The signature1 and signature2 shown correct.
(2). 
QP.LoadFromFile(L"c:\\TEST\\B.pdf",L"");
std::string                FileString(QP.SaveToString()); // save to string
nSignProcessID = QP.NewSignProcessFromString(FileString,L"");
QP.SetSignProcessPFXFromFile(nSignProcessID,swPFXFile,swPassword);
...................
QP.EndSignProcessToFile(nSignProcessID,L"c:\\test\\C.pdf");   
(3).
QP.LoadFromFile(L"c:\\TEST\\B.pdf",L"");
QP.SaveToFile(L"c:\\TEST\\tmp.pdf");
nSignProcessID = QP.NewSignProcessFromFile(L"C:\\TEST\\tmp.pdf",L"");
QP.SetSignProcessPFXFromFile(nSignProcessID,swPFXFile,swPassword);
........................
QP.EndSignProcessToFile(nSignProcessID,L"c:\\test\\C.pdf");   
The signature1 shown incorrect, the signature2 shown correct in 2,3.
 
In (2),(3), save to file or string first, then signature process to save to c.pdf, the signature become incorrect.
In (1), use signature process directly, the signature are correct. 
They are different in SaveToFile/SaveToString.






Posted By: mLipok
Date Posted: 26 Jan 15 at 3:53PM
Honestly I have never used the option of signing PDF files in this library.
My previous answers were general in nature.

As for your last question, unfortunately I am not able to answer now.


-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: mLipok
Date Posted: 26 Mar 15 at 8:47PM
btw. 
I re read
Debenu Quick PDF Library 11 Developer Guide.pdf

and here is explanation

Processing digitally signed PDF files
Any changes that you make to a PDF after it has been digitally signed will invalidate the digital
signature. PDF files that contain digital signatures must be incrementally updated -- meaning
that the contents of the PDF are updated without rewriting the entire file by way of appending
changes to the end of the file. If digitally signed PDF files are not updated this way then the
digital signature will not only be invalidated, but it will be completely broken too.

When using Debenu Quick PDF Library it’s important to note that the combination of
LoadFromFile and SaveToFile does not incrementally update the file. Instead it completely
rewrites the contents of the PDF and breaks the digital signature. If you’re working with a PDF
that has a digital signature and you do not want to break or remove the digital signature, then
you should not use the SaveToFile function.

If you need to modify a PDF that has been digitally signed then you should use the DAOpenFile
and DAAppendFile functions as the DAAppend function does incrementally update PDF files,
which means that the digital signature will be invalidated, but not broken.




-------------
Here you can find description how to test my examples:
http://www.quickpdf.org/forum/forum_posts.asp?TID=2932&PID=12600&title=drawcapturedpagematrix-matrix-howto#12600


Posted By: Rowan
Date Posted: 29 Mar 15 at 1:05PM
I should add that the http://www.debenu.com/docs/pdf_library_reference/AppendToFile.php" rel="nofollow - AppendToFile function has been added to the regular functions as well, so you can use it there too. I will update this in the developer guide.

As for the LoadFromFile - > SaveToFile example, this re-writes the file. I presume when you do something similar in Adobe Reader / Acrobat it sees that it contains a digital signature and makes no changes to the document, just saves an identical copy of the file that was loaded. We're working at a lower level so the developer has to implement checks like that in their applications, in the same way that the developers of Adobe products do.

With regards to your other question, you need to use the AppendToFile function. That will do an incremental update. This will still invalidate the previous signature that was added to the document -- as the document has changed -- but it should not *break* the previous signature, which is the crucial point.






Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk