Java Code Examples for org.apache.pdfbox.pdmodel.PDDocument.addSignature()

The following are Jave code examples for showing how to use addSignature() of the org.apache.pdfbox.pdmodel.PDDocument class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: esup-ecandidat   File: CreateSignaturePdf.java   Source Code and License Vote up 6 votes
/** Signe un document PDF
 * @param inStream
 * @param name
 * @param location
 * @param reason
 * @param contactInfo
 * @return l'inputStream
 * @throws IOException
 */
public InputStream signPdf(ByteArrayInOutStream inStream, String name, String location, String reason, String contactInfo) throws IOException {
	if (inStream == null) {
		throw new FileNotFoundException("Document for signing does not exist");
	}
	// sign
	PDDocument doc = PDDocument.load(inStream.getInputStream());		

	// create signature dictionary
	PDSignature signature = new PDSignature();
	signature.setFilter(PDSignature.FILTER_ADOBE_PPKLITE);
	signature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_DETACHED);
	signature.setName(name);
	signature.setLocation(location);
	signature.setContactInfo(contactInfo);
	signature.setReason(reason);

	// the signing date, needed for valid signature
	signature.setSignDate(Calendar.getInstance());

	// register signature dictionary and sign interface
	doc.addSignature(signature, this);

	// write incremental (only for signing purpose)
	ByteArrayInOutStream outStream = new ByteArrayInOutStream();
	doc.saveIncremental(outStream);
	doc.close();
	inStream.close();
	return outStream.getInputStream();
}