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.

Fri Dec 09, 2022 11:33 pm

I'm trying to add more than one digital signature to the same file simultaneously, but the second one invalidates the first one, do I need to set any special parameters?
//Load a pdf document
PdfDocument doc = new PdfDocument();
doc.loadFromBytes(pdfBytes);

for (RequestDataSignatureModel value : signatures) {
String certPfxKey = "CERT_" + value.getCertKey().toString() + "_PFX";
String certPfxPasswordKey = "CERT_" + value.getCertKey().toString() + "_PFX_PASSWORD";
byte[] certPfxFile = GoogleCloudSecretHelper.accessSecret(
certPfxKey,
"latest"
).getPayload().getData().toByteArray();
String certPfxPassword = GoogleCloudSecretHelper.accessSecret(
certPfxPasswordKey,
"latest"
).getPayload().getData().toString("UTF-8");
//Load the certificate
PdfCertificate pdfCert = new PdfCertificate(certPfxFile, certPfxPassword);

//Create a PdfSignature object and specify its position and size
PdfSignature signature = new PdfSignature(doc, doc.getPages().get(0), pdfCert, value.getName());
Rectangle2D rect = new Rectangle2D.Float();
rect.setFrame(new Point2D.Float(
(value.getX().intValue() > 0) ? value.getX().floatValue() : (float) (doc.getPages().get(0).getActualSize().getWidth() + value.getX().doubleValue()),
(value.getY().intValue() > 0) ? value.getY().floatValue() : (float) (doc.getPages().get(0).getActualSize().getHeight() + value.getY().doubleValue())),
new Dimension(220, 50)
);
signature.setBounds(rect);

//Set the graphics mode
signature.setGraphicMode(GraphicMode.Sign_Image_And_Sign_Detail);
signature.setSignTextAlignment(SignTextAlignment.Left);
//Set the signature content
signature.setName("Digitalmente assinado por:\n" + value.getName() + "\n\n");
signature.setDistinguishedNameLabel("CNPJ: ");
signature.setDistinguishedName(value.getDocument() + "\n\n");
signature.setDateLabel(MessageFormat.format("Data: {0} \n\n\n", dateFormat.format(new Date())));
signature.setDate(null);
signature.setSignImageSource(
PdfImage.fromFile(
certImg.getPath()
)
);
signature.setSignImageLayout(SignImageLayout.Stretch);

//Set the signature font
signature.setSignDetailsFont(new PdfFont(PdfFontFamily.Helvetica, 7f, PdfFontStyle.Regular));

//Set the document permission
signature.setDocumentPermissions(PdfCertificationFlags.Forbid_Changes);
signature.setCertificated(true);
}

//Save to file
Path signedFilePath = Paths.get(tempDir.getPath() + fileSeparator + executionId + ".pdf");
File singedFile = signedFilePath.toFile();

gustavodamazio
 
Posts: 1
Joined: Thu Dec 08, 2022 7:17 pm

Mon Dec 12, 2022 2:48 am

Hi,

Thanks for your inqiury.
Please refer to the following code to add multiple digital signatures in the same file.

Code: Select all
   
            //Create PDF document
            PdfDocument document = new PdfDocument();

            //Load the PDF document
            document.LoadFromFile("sample.pdf");

            //Create X509Certificate2
            X509Certificate2 x509 = new X509Certificate2("test.pfx", "e-iceblue");


            //Create PdfOrdinarySignatureMaker
            PdfOrdinarySignatureMaker signatureMaker = new PdfOrdinarySignatureMaker(document, x509);

            //Set signature appearance
            PdfSignatureAppearance signatureAppearance = new PdfSignatureAppearance(signatureMaker.Signature);
            signatureAppearance.NameLabel = "Signer:";
            signatureAppearance.ContactInfoLabel = "ContactInfo:";
            signatureAppearance.LocationLabel = "Location:";
            signatureAppearance.ReasonLabel = "Reason:";

            //Set details for the signature1
            PdfSignature signature1 = signatureMaker.Signature;
            signature1.Name = "Tom";
            signature1.ContactInfo = "Tom Tang";
            signature1.Location = "China";
            signature1.Reason = "protect document data";

            //Add the first signature
            signatureMaker.MakeSignature("Signature1", document.Pages[0], 100, 300, 120, 70, signatureAppearance);


            //Set details for the signature2
            PdfSignature signature2 = signatureMaker.Signature;
            signature2.Name = "Bob";
            signature2.ContactInfo = "Bob Li";
            signature2.Location = "China";
            signature2.Reason = "protect document data";

            //Add the second signature
            signatureMaker.MakeSignature("Signature2", document.Pages[0], 400, 300, 120, 70, signatureAppearance);

            //Save the PDF document
            string outpdf = "output.pdf";
            document.SaveToFile(outpdf, FileFormat.PDF);


If you have further questions, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Wed Dec 14, 2022 9:45 am

Hi,

Greetings from E-iceblue
Did the code I provide meet your requirement? I’m looking forward to your feedback. If there are any problems with our products, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Fri Oct 06, 2023 4:59 pm

I was trying with the free Edition, but I required a temporaly license for my test scenario but I'm still waiting could you please help me with the temporally license key so I can show the demo and make a purchase ASAP.

hmero
 
Posts: 1
Joined: Fri May 10, 2019 5:48 pm

Sat Oct 07, 2023 3:58 am

Hi,

Thanks for your interests in our product.
Please visit this link to request a temporary license(https://www.e-iceblue.com/TemLicense.html) or contact our sales team(sales@e-iceblue.com). If you need further assistance, just feel free to contact us. We are here to help.

Best Regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.PDF