本文整理匯總了Java中org.apache.pdfbox.pdmodel.PDDocument.addSignature方法的典型用法代碼示例。如果您正苦於以下問題:Java PDDocument.addSignature方法的具體用法?Java PDDocument.addSignature怎麽用?Java PDDocument.addSignature使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.pdfbox.pdmodel.PDDocument
的用法示例。
在下文中一共展示了PDDocument.addSignature方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: signPdf
import org.apache.pdfbox.pdmodel.PDDocument; //導入方法依賴的package包/類
/** 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();
}