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

Free Support Forum - aspose.com

Signature Panel - PdfFileSignature class

I can add my digital signature by using PdfFileSignature and PKCS1 classes. However, I found that the signature panel cannot be shown. Is it normal that the Signature Panel cannot be shown in the PDF signed by Aspose?

public void savePdfWord() throws Exception {

	Enumeration<URL> urls = GetAssSummReport.class.getClassLoader().getResources("Aspose.Total.Java.lic"); 
	
	if (urls != null && urls.hasMoreElements()) {
		URL asposeLicense = urls.nextElement();
		License license = new License();
		license.setLicense(asposeLicense.openStream());
	}
	
	String keyPath = "C:\\Shared\\20190809\\key.pfx";
	String outputPath  ="C:\\Shared\\20190809\\output.pdf";
	
	PdfFileSignature pdfSignSingle = new PdfFileSignature();
	Document pdfDocument = new Document("C:\\Shared\\20190809\\input.pdf");
	PKCS1 pkc = new PKCS1(keyPath,"changeit");
	pkc.setReason("Testing");
	pkc.setLocation("Location");
	pdfSignSingle.bindPdf(pdfDocument);
	pdfSignSingle.sign(1, true, new java.awt.Rectangle(100, 100, 300, 50), pkc);
	pdfSignSingle.setSignatureAppearance("C:\\Shared\\20190809\\sign.jpg"); 
	pdfSignSingle.save(outputPath); 
	pdfDocument.close();

}

ask_aspose.jpg (88.0 KB)

@jimmy.hkecic

Would you kindly share source and output PDF document with us so that we can test the scenario in our environment and address it accordingly.

public void savePdfWord() throws Exception {
		
		Enumeration<URL> urls = GetAssSummReport.class.getClassLoader().getResources("Aspose.Total.Java.lic"); 
		
		if (urls != null && urls.hasMoreElements()) {
			URL asposeLicense = urls.nextElement();
			License license = new License();
			license.setLicense(asposeLicense.openStream());
		}
		
		String keyPath = "C:\\Shared\\20190809\\206532_cert.pfx";
		String outputPath  ="C:\\Shared\\20190809\\206532_output.pdf";
		
		PdfFileSignature pdfSignSingle = new PdfFileSignature();
		Document pdfDocument = new Document("C:\\Shared\\20190809\\206532_input.pdf");
		PKCS1 pkc = new PKCS1(keyPath,"changeit");
		pkc.setReason("Testing by Reiko");
		pkc.setLocation("HKECIC");
		pdfSignSingle.bindPdf(pdfDocument);
		pdfSignSingle.sign(1, true, new java.awt.Rectangle(100, 100, 300, 50), pkc);
		pdfSignSingle.setSignatureAppearance("C:\\Shared\\20190809\\206532_sign.jpg"); 
		pdfSignSingle.save(outputPath); 
		pdfDocument.close();
	}

206532_output.pdf (85.9 KB)

@jimmy.hkecic,

Can you please share source file as well. You have only shared output PDF file with us. We need source files as well which you are using on your end so that we may further investigate to help you out.

Please find the source file as attached.

206532_input.pdf (27.7 KB)

@jimmy.hkecic

We tried using following code snippet with Aspose.PDF for Java 19.11 and were unable to notice any issue. The signature panel was visible in the output PDF.

Digitally Sign PDF

String inputFile = dataDir + "206532_input.pdf";
String outSignedFile = dataDir + "out_19.11.pdf";
// Create PdfFileSignature instance
com.aspose.pdf.facades.PdfFileSignature pdfSignSingle = new com.aspose.pdf.facades.PdfFileSignature();
// Bind the source PDF by reading contents of Stream
pdfSignSingle.bindPdf(inputFile);
PKCS7 pkcs = new PKCS7(dataDir + "mykey2.pfx", "aa");
pkcs.setReason("");
pkcs.setContactInfo("");
pkcs.setDate(null);
SignatureCustomAppearance sca = new SignatureCustomAppearance();
sca.setDateSignedAtLabel(null);
sca.setDigitalSignedLabel(null);
sca.setShowReason(false);
sca.setShowLocation(false);
sca.setShowContactInfo(false);

pkcs.setCustomAppearance(sca);
pdfSignSingle.sign(1, true, new java.awt.Rectangle(350, 80, 150, 50), pkcs);
// Set image for signature appearance
pdfSignSingle.setSignatureAppearance(dataDir + "avatar.png");
// Save final output
pdfSignSingle.save(outSignedFile);

out_19.11.pdf (95.8 KB)

Would you kindly try using latest version of the API and in case you still face any issue, please let us know.