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”);
}
}