Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jan 29, 2018 1:41 pm

If I digitally sign a PDF with more then one page and open the singed PDF in Acrobat Reader then I see 2 signatures (one for each page), the first signature is OK but the second shows the document has been modified since it was signed.

In the code I sign each page individually since the PdfSignature class constructor requires a PdfBasePage as a parameter, is it ok? or should I only sign the first or last page?

Attached a screenshot and here is the code I'm using:

PdfCertificate digi = new PdfCertificate("c://temp//test1.pfx", "123456");

PdfSignature signature = new PdfSignature(doc, doc.Pages[0], digi, "Bumpyard");
signature.ContactInfo = "Bumpyard";
signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

signature = new PdfSignature(doc, doc.Pages[1], digi, "Bumpyard");
signature.ContactInfo = "Bumpyard";
signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

doc.SaveToFile("DrawText.pdf");
doc.Close();

bumpyard
 
Posts: 8
Joined: Mon Jan 15, 2018 8:48 am

Tue Jan 30, 2018 6:41 am

Hello,

Thanks for your inquiry.
Kindly note that the multiple-time signing requires the behavior of saving and reload the document for each signing as well as the license. In addition, you need comment out the
Code: Select all
//signature.Certificated = true;
because the property "Certificated" can only be set once for each document.
Please refer to the code below.
Code: Select all
Spire.License.LicenseProvider.SetLicenseKey("Your license key");
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"input.pdf");
PdfCertificate digi = new PdfCertificate("c://temp//test1.pfx", "123456");

PdfSignature signature = new PdfSignature(doc, doc.Pages[0], digi, "Bumpyard");
signature.ContactInfo = "Bumpyard";
signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

//Save and reload, then sign again.
MemoryStream ms = new MemoryStream();
doc.SaveToStream(ms, FileFormat.PDF);
PdfDocument doc1 = new PdfDocument();
doc1.LoadFromStream(ms);

signature = new PdfSignature(doc1, doc1.Pages[1], digi, "Bumpyard");
signature.ContactInfo = "Bumpyard";
//Pay attentaion, the "Certificated" can only set once for each document.
//signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

doc1.SaveToFile("DrawText.pdf");


Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jan 30, 2018 8:48 am

Thank you for the answer, I also want to ask if it's possible to sign only once on all the pages of the PDF - meaning without providing a specific page to the PdfSignature class constructor?

bumpyard
 
Posts: 8
Joined: Mon Jan 15, 2018 8:48 am

Tue Jan 30, 2018 9:29 am

Hi bumpyard,

Thanks for your response.
Sorry that the feature is not available at present, yet the news from our dev team is that it is reachable theoretically. We will consider adding the new feature to our future upgrade. Once there's any update, I will let you know.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Tue Jan 30, 2018 12:40 pm

Hi

I wrote the code as you suggested but when I open the final PDF in Acrobat Reader I see 2 signatures but the first signature is not valid, the Acrobat Reader display it's not valid since one page modified, attached a screen shot.

By the way, if I only sign the first page then is it guarantees that the all document had not been modified after the sign?

Here is my code:

PdfDocument doc = new PdfDocument("c://temp//test.pdf");
PdfCertificate digi = new PdfCertificate("c://temp//test.pfx", "123456");

PdfSignature signature = new PdfSignature(doc, doc.Pages[0], digi, "Bumpyard");
signature.ContactInfo = "Bumpyard";
signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

//Save and reload, then sign again.
MemoryStream ms1 = new MemoryStream();
doc.SaveToStream(ms1, FileFormat.PDF);
PdfDocument doc1 = new PdfDocument();
doc1.LoadFromStream(ms1);

signature = new PdfSignature(doc1, doc1.Pages[1], digi, "Bumpyard");
signature.ContactInfo = "Bumpyard";
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

//Save doc file.
doc1.SaveToFile("DrawText.pdf");
doc1.Close();

bumpyard
 
Posts: 8
Joined: Mon Jan 15, 2018 8:48 am

Wed Jan 31, 2018 1:37 am

Hello bumpyard,

Thanks for your reply.
Please make sure you had applied the license
Code: Select all
Spire.License.LicenseProvider.SetLicenseKey("Your license key");

and use the latest version(Spire.PDF Pack Version:3.10). Without license appliance, I could reproduce the issue you demonstrated.
If the issue still troubles you, please send your sample document to us([email protected]) and share your testing environment.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Jan 31, 2018 9:19 am

You right, I didn't include my license since it was only a test program, once I did it everything worked!
Thank you very much.

But you didn't answered my second question:
"By the way, if I only sign the first page then is it guarantees that the all document had not been modified after the sign?"
I asked this because if a document contains 50 pages then if I sign every page then the Acrobat Reader will show it have 50 signatures! it a lot of signatures and a bad user experience.

And another question, I currently set the license with a xml file by using the command:
Spire.License.LicenseProvider.SetLicenseFileFullPath(<xml path>)

But I would prefer to do that by using the command that you sent:
Spire.License.LicenseProvider.SetLicenseKey(<license key>)

Are those two commands equal?

bumpyard
 
Posts: 8
Joined: Mon Jan 15, 2018 8:48 am

Wed Jan 31, 2018 9:51 am

Hello,

Thanks for your feedback.
If you only sign the first page(once), Acrobat Reader will display that "document had not been modified after the sign". As I told before, it is not available to sign only once to all the pages with document unmodified at present. From the standard of Adobe, it seems that one page corresponds to one signature, that means no matter what times you sign, even for only once, as long as you signed to all the pages, the number of the signatues in the left hand would be the same as the page numbe . One signature for one signature. Oue dev team would do a further investigation on that.
As for the Spire.License.LicenseProvider.SetLicenseFileFullPath(<xml path>) and Spire.License.LicenseProvider.SetLicenseKey(<license key>), they are both for license applicance, yet I recommend the later one, baceuse in some cases, the first method would cause the unrecognition of the license file due to the lack of permission or other reasons.

Sincerely,
Jane
E-iceblue support team
User avatar

Jane.Bai
 
Posts: 1156
Joined: Tue Nov 29, 2016 1:47 am

Wed Jan 31, 2018 10:42 am

I don't understand your answer, I will try to rephrase my question:

If I use the command:
PdfSignature signature = new PdfSignature(doc, doc.Pages[0], digi, "Bumpyard")
Which receives specific page (doc.Pages[0]) as a parameter, then if the document contains 2 pages I need to use this command 2 times (for page 1 and page 2).
In this case the Acrobat Reader will show that the PDF has 2 signatures revisions as seen in the attached screen shot.
If the document has 50 pages then the Acrobat Reader will display 50 revisions which is not good.

My question is this: if Instead of signing each page separately I only sign the first page (or maybe the last page) then is it equivalent to sign each page separately in terms of ensuring the entire document had not been modified after the sign?
(If you don't know the answer to this then it's ok, but please don't give me a confusing answer which don't answer what I asked)

Thanks.

bumpyard
 
Posts: 8
Joined: Mon Jan 15, 2018 8:48 am

Thu Feb 01, 2018 6:32 am

Hello,

Sorry for making you confuse. Digital signature is for a whole document, not for one page, when use that command many times, it indicates that the document will been signed many times, our product mimics the adobe behaviors, hence, the method of our product specifics the page as a parameter to let user decide which page the signature should be put, so you only need to specific one page, it will sign the entire document.

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Return to Spire.PDF