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.

Wed Aug 05, 2020 7:35 am

Hi,
I want to build signature feature in pdf file like the image I attached below (image file 1), I use Foxit tool to do it, the signatures are sent for each and every signer on foxit is very good,
Please ask: How to sign on Spire.Doc C # like on Foxit
Can you have a sample code for me?
thank you very much

thuytd86
 
Posts: 13
Joined: Wed Oct 16, 2019 4:17 am

Wed Aug 05, 2020 10:43 am

Hello,

Thanks for your inquiry.
Kindly note that to sign a document multiple times, you need to save the pdf after a signature, and then load the pdf and sign the document again, as shown below.
Code: Select all
            String input = @"input.pdf";
            PdfDocument doc = new PdfDocument();
            doc.LoadFromFile(input);
            //Load the certificate
            String pfxPath = @"xxx.pfx";
            PdfCertificate cert = new PdfCertificate(pfxPath, "e-iceblue");

            PdfSignature signature = new PdfSignature(doc, doc.Pages[0], cert, "signature0");
            signature.Bounds = new RectangleF(new PointF(90, 100), new SizeF(270, 90));

            //Load sign image source.
            signature.SignImageSource = PdfImage.FromFile(@"Logo.png");
            //Set the dispay mode of graphics, if not set any, the default one will be applied
            signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
            signature.NameLabel = "Signer:";
            signature.Name = "Gary";
            signature.ContactInfoLabel = "ContactInfo:";
            signature.ContactInfo = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
            signature.DateLabel = "Date:";
            signature.Date = DateTime.Now;
            signature.LocationInfoLabel = "Location:";
            signature.LocationInfo = "Chengdu";
            signature.ReasonLabel = "Reason: ";
            signature.Reason = "The certificate of this document";
            signature.DistinguishedNameLabel = "DN: ";
            signature.DistinguishedName = signature.Certificate.IssuerName.Name;
            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
            //signature.Certificated = true;
            //Set fonts. if not set, default ones will be applied.
            signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
            signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
            //Set the sign image layout mode
            signature.SignImageLayout = SignImageLayout.None;

            //save the pdf and then load it and sign again
            MemoryStream ms = new MemoryStream();
            doc.SaveToStream(ms);
            doc.LoadFromStream(ms);

            signature = new PdfSignature(doc, doc.Pages[0], cert, "signature1");
            signature.Bounds = new RectangleF(new PointF(90, 300), new SizeF(270, 90));
            //Load sign image source.
            signature.SignImageSource = PdfImage.FromFile(@"Logo.png");

            //Set the dispay mode of graphics, if not set any, the default one will be applied
            signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;
            signature.NameLabel = "Signer:";

            signature.Name = "Gary";

            signature.ContactInfoLabel = "ContactInfo:";
            signature.ContactInfo = signature.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
            signature.DateLabel = "Date:";
            signature.Date = DateTime.Now;
            signature.LocationInfoLabel = "Location:";
            signature.LocationInfo = "Chengdu";
            signature.ReasonLabel = "Reason: ";
            signature.Reason = "The certificate of this document";
            signature.DistinguishedNameLabel = "DN: ";
            signature.DistinguishedName = signature.Certificate.IssuerName.Name;
            signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
            //signature.Certificated = true;

            //Set fonts. if not set, default ones will be applied.
            signature.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
            signature.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);

            //Set the sign image layout mode
            signature.SignImageLayout = SignImageLayout.None;
            doc.SaveToFile(@"DigitalSignature.pdf");
            doc.Close();

Also, if you are using our commercial version, you need to apply a valid license in your application, otherwise it will add warning message to the PDF, which changes the content of the document and will cause the signature to become invalid. We are willing to provide a temporary license (one month free) to help you remove the warning message. You can contact our sales team (sales@e-iceblue.com) to get it.
If there are any questions, please feel free to write back.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Aug 05, 2020 2:43 pm

Hi,
Thanks for the feedback.
I have done as the above code, everything works fine, thanks a lot.
SO,
But my problem is as follows.
But my problem is as follows.
The first time the user will signature on the PDF file through the software using the Spire.PDF library, and save the resulting file on the server, and the server automatically sends a notification email to the next person to signature .
Next step.
The second person receives the previous person's signature file,
As the dark picture has attached.
Question,
How to add the signature of the 2nd person without losing the signature of the 1st person, this is very important because the 3rd signer can see the 1st and 2nd signed through view this version on pdf
How to solve this problem, thank you very much
I am using the commercial version
Thanks very much

thuytd86
 
Posts: 13
Joined: Wed Oct 16, 2019 4:17 am

Thu Aug 06, 2020 2:32 am

Hello,

Thanks for your response.
Below is the code for your reference. Please note that you cannot make any changes to the contents of the file except during the signing process, otherwise the signature will become invalid. If there is any question, please feel free to contact us.
Code: Select all
        static void Main(string[] args)
        {

            string input = @"signature.pdf";
            string outpath1 = Sign(input, "out1.pdf", new RectangleF(new PointF(90, 100), new SizeF(270, 90)));
            string outpath2 = Sign(outpath1, "out2.pdf", new RectangleF(new PointF(90, 300), new SizeF(270, 90)));
            //...
        }

        public static string Sign(String inputPath, string outputPath, RectangleF rect)
        {
            PdfDocument doc1 = new PdfDocument();
            doc1.LoadFromFile(inputPath);
            //Load the certificate
            PdfCertificate cert1 = new PdfCertificate(@"xxx.pfx", "password");

            PdfSignature signature1 = new PdfSignature(doc1, doc1.Pages[0], cert1, "signature0");
            signature1.Bounds = rect;

            //Load sign image source.
            signature1.SignImageSource = PdfImage.FromFile(@"Logo.png");
            //Set the dispay mode of graphics, if not set any, the default one will be applied
            signature1.GraphicsMode = GraphicMode.SignImageAndSignDetail;
            signature1.NameLabel = "Signer:";
            signature1.Name = "Gary";
            signature1.ContactInfoLabel = "ContactInfo:";
            signature1.ContactInfo = signature1.Certificate.GetNameInfo(System.Security.Cryptography.X509Certificates.X509NameType.SimpleName, true);
            signature1.DateLabel = "Date:";
            signature1.Date = DateTime.Now;
            signature1.LocationInfoLabel = "Location:";
            signature1.LocationInfo = "Chengdu";
            signature1.ReasonLabel = "Reason: ";
            signature1.Reason = "The certificate of this document";
            signature1.DistinguishedNameLabel = "DN: ";
            signature1.DistinguishedName = signature1.Certificate.IssuerName.Name;
            signature1.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
            //signature.Certificated = true;
            //Set fonts. if not set, default ones will be applied.
            signature1.SignDetailsFont = new PdfFont(PdfFontFamily.TimesRoman, 10f);
            signature1.SignNameFont = new PdfFont(PdfFontFamily.Courier, 15);
            //Set the sign image layout mode
            signature1.SignImageLayout = SignImageLayout.None;

            doc1.SaveToFile(outputPath);
            doc1.Close();
            return outputPath;
        }


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Aug 12, 2020 1:46 am

Hello,

Greetings from E-iceblue!
Does this code work well for you? Looking forward to your further feedback.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Aug 12, 2020 2:39 am

Everything works very well but only unfortunately does not support UTF8
Eg
signature.Bounds = rectf;
signature.SignImageSource = PdfImage.FromFile (@ "E: \ chu_ky_remove_background_2.png");
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;

signature.NameLabel = "Signer:";
signature.Name = "TRAN DINH THUY";
signature.Reason = "Signer by TRAN DINH THUY";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
signature.Certificated = true;

The system does not support TF8
thank for the support

thuytd86
 
Posts: 13
Joined: Wed Oct 16, 2019 4:17 am

Wed Aug 12, 2020 6:05 am

Hello,

Thanks for your feedback.
Sorry I'm not quite sure what you mean by "does not support UTF8". To help us better understand your issue, could you please provide more detailed information? Some screenshots may be helpful. Thanks in advance.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Aug 12, 2020 7:49 am

Hi Team,
Thank you team for supporting,
I sent the team the code signature as follows:

String pfxPath = @ "C: \ A \ .... pfx";
PdfCertificate cert = new PdfCertificate (pfxPath, "xxxxx");
PdfSignature signature = new PdfSignature (doc, doc.Pages [1], cert, "TRAN DINH THUY");

signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;

RectangleF rectf = new RectangleF (new PointF (postx, posty - 55), new SizeF (200, 90));
signature.Bounds = rectf;
signature.SignImageSource = PdfImage.FromFile (@ "E: \ chu_ky_remove_background_2.png");
signature.GraphicsMode = GraphicMode.SignImageAndSignDetail;


signature.NameLabel = "Signer:";
signature.Name = "TRẦN DÌNH THỦY";
signature.Reason = "Signer by TRẦN DÌNH THỦY";
signature.DateLabel = "Date:";
signature.Date = DateTime.Now;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill | PdfCertificationFlags.ForbidChanges;
signature.Certificated = true;

I have declared the signature.Name = "TRAN DINH THUY" property;
Once done, signature.Name results do not display the correct content for the purpose (TRẦN DÌNH THỦY). Please see attached Photo file
Thank you team

thuytd86
 
Posts: 13
Joined: Wed Oct 16, 2019 4:17 am

Wed Aug 12, 2020 9:37 am

Hello,

Thanks for your more information.
To achieve your needs, please refer to the following code snippet to set "SignDetailsFont" and "SignNameFont" properties. If there is any other question, just feel free to let us know.
Code: Select all
            //Set fonts
            signature.SignDetailsFont = new PdfTrueTypeFont(new Font("Calibri", 10), true);
            signature.SignNameFont = new PdfTrueTypeFont(new Font("Calibri", 10), true);

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Wed Aug 12, 2020 1:00 pm

Hi,
Everything works great, thanks team

thuytd86
 
Posts: 13
Joined: Wed Oct 16, 2019 4:17 am

Thu Aug 13, 2020 1:31 am

Hello,

You are welcome.
If you encounter any issues related to our product in the future, just feel free to contact us.
Wish you all the best!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF