We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue with digital sign of PDF files

Hi Team,


I am trying to digital sign pdf file using aspose pdf api. Below is the code.
This works fine as the digital certificate is .pfx but I have another digital certificate which is having .p12 extension. I am not able to sign pdf using .p12 digital certificates.
Can you please help me in this regard. (is that limitation in aspose pdf api)

package com.test;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import com.aspose.pdf.License;
import com.aspose.pdf.PKCS1;

public class Signing {
public static void main(String[] args) throws Exception
{
String sourceFilePath=“D:\dwo.pdf”;
String destFilePath=“D:\two_ds_pfx.pdf”;
String selectedDigitalFile=“D:/test.pfx”;
File document = new File(sourceFilePath);
com.aspose.pdf.facades.PdfFileSignature pdfSign = new com.aspose.pdf.facades.PdfFileSignature();
pdfSign.bindPdf(new BufferedInputStream(new FileInputStream(sourceFilePath)));
System.out.println(“pdf file binded”);
//create a rectangle for signature location
java.awt.Rectangle rect = new java.awt.Rectangle(100, 100, 200, 100);
//set signature appearance
pdfSign.setSignatureAppearance(“D:/”+“Sign.png”);
//create any of the three signature types
PKCS1 signature = new PKCS1(selectedDigitalFile, “india123”);
System.out.println(“PKCS1 instantiated”);
pdfSign.sign(1, “”, “”, “”, true, rect, signature);
System.out.println(“sign done”);
//save output PDF file
pdfSign.save(destFilePath);
System.out.println(“sign done & saved”);
}
}

Hi Surabhi,


Thanks for your inquiry. I have tested the scenario using Aspose.Pdf for Java 10.9.0 as following and unable able to notice any issue. Please download and try latest version of Aspose.Pdf for Java, hopefully it will resolve the issue. However if the issue persist then please share your sample source documents and certificate, we will look into it and guide you accordingly.

PKCS1 signature = new PKCS1(myDir+ “cert.p12”, “password”);

We are sorry for the inconvenience caused.

Best Regards,