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.

Tue Dec 11, 2018 7:35 pm

Hello,
I got a task from my employer to test Spire.PDF before buying license.
The main point is PDF signing with smart card sertificate.
I am using this code (sertificate replaced into Demo):
Code: Select all
static void SignTest(string SourceFile, string DestFile)
        {
            Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument(SourceFile);
            PdfCertificate cert = new PdfCertificate("Demo.pfx", "e-iceblue");

            var signature = new Spire.Pdf.Security.PdfSignature(doc, doc.Pages[0], cert, "demo");
            signature.Bounds = new RectangleF(new PointF(280, 600), new SizeF(260, 90));

            signature.NameLabel = "ąčęėįšųūž my signature";
            signature.DateLabel = "Date: ";
            signature.Date = DateTime.Now;

            signature.DocumentPermissions = PdfCertificationFlags.ForbidChanges;
           
            doc.SaveToFile(DestFile);
        }

got two problems to solve:
1. when signing timestamped PDF, timestamp got broken. How to append my signature, without document changes and breaking of timestamp? (picture1 added)
2. when using special language letters (all listed in signature.NameLabel property), got text like in picture2.

Could You please help me with these problems?

julaj
 
Posts: 5
Joined: Tue Dec 11, 2018 6:19 pm

Wed Dec 12, 2018 5:48 am

Hi,

Thank you for your inquiry.
Kindly note that the multiple signing requires the behavior of saving and reloading the document for each signing as well as the license appliance.
Our sales team has sent a temporary license of Spire.PDF to you, please apply the license according to the guide: https://www.e-iceblue.com/Tutorials/Licensing/Licensing.html#Apply_by_Key
Below is the code for your kind reference for issue 1.
Code: Select all
Spire.License.LicenseProvider.SetLicenseKey("Your license key");
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"input.pdf");

//first sign
PdfCertificate digi1 = new PdfCertificate(@"sample.pfx", "e-iceblue");
PdfSignature signature1 = new PdfSignature(doc, doc.Pages[0], digi1, "First");
signature1.ContactInfo = "First";
signature1.Certificated = true;
signature1.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

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

//second sign
PdfCertificate digi2 = new PdfCertificate(@"sample.pfx", "e-iceblue");
PdfSignature signature2 = new Spire.Pdf.Security.PdfSignature(doc1, doc1.Pages[0], digi2, "second");
signature2.Bounds = new RectangleF(new PointF(280, 600), new SizeF(260, 90));
signature2.NameLabel = "ąčęėįšųūž my signature";
signature2.DateLabel = "Date: ";
signature2.Date = DateTime.Now;
signature2.DocumentPermissions = PdfCertificationFlags.ForbidChanges;

doc1.SaveToFile("MultiSign.pdf");

As for the second issue, I have reproduced it and logged it in our bug tracking system.
Once there's an 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

Wed Dec 12, 2018 7:18 am

Thank you very much for fast reply.
As i see, first problem was in free version watermarks.
Timestamp is not broken, but now my signature is not visible, could You fix it?
Appended picture when signing simple file and timestamped.
Sorry, I can not send timestamped file sample as it contains sensitive data.

julaj
 
Posts: 5
Joined: Tue Dec 11, 2018 6:19 pm

Wed Dec 12, 2018 7:35 am

Hi,

Are you drawing the signature into a rectangle? If not, it would be invisible.
Just set the bounds for the certificate to make it visible like below.
Code: Select all
signature.Bounds = new RectangleF(new PointF(x, y), new SizeF(width, height));

Also, please download the latest hotfix Spire.PDF Pack(Hot Fix) Version:4.12.2 which has a better performance.
If there's still any problem, just share your complete code.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Wed Dec 12, 2018 7:56 am

Oh, sorry, found my fault: rectange coordinates was set outside the document visible part.
I would recommend other users to check document boundaries before setting rectangle.
Now everything is perfect. Thank You.

Will wait news about solving second problem.

julaj
 
Posts: 5
Joined: Tue Dec 11, 2018 6:19 pm

Wed Dec 12, 2018 8:00 am

Hi,

Thank you for your feedback.
Will inform you once there's any good news.:)

Sincerely,
Jane
E-iceblue support team
User avatar

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

Wed Dec 12, 2018 10:23 am

Hi,

After our dev team further investigation, regret to tell that the issue could not be fixed.
It is because that we draw text using the ANSI encoding by default while the content "ąčęėįšųūž" are not included in the ANSI encoding.
Apologize for that.

Sincerely,
Jane
E-iceblue support team
User avatar

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

Wed Dec 12, 2018 10:42 am

Hi,
very pity situation :(

And it is no workarounds or posibility to draw UTF-8 encoding?

julaj
 
Posts: 5
Joined: Tue Dec 11, 2018 6:19 pm

Wed Dec 12, 2018 12:27 pm

Finally, found answer by myself :)
simply add lines:
Code: Select all
 PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f), true);
            signature.SignDetailsFont = font;

julaj
 
Posts: 5
Joined: Tue Dec 11, 2018 6:19 pm

Thu Dec 13, 2018 2:22 am

Hi,

Glad to hear that you have found the solution.
Yes, if you are going to draw the special characters, please set a font which supports the characters.
Anyway, you are great! :)

Sincerely,
Jane
E-iceblue support team
User avatar

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

Return to Spire.PDF