Import? com . spire . pdf . *;
Import? com . spire . pdf . graphics . pdf image;
Import? com . spire . pdf . graphics . pdftruetypefont;
Import? com . spire . pdf . security . graphic mode;
Import? com . spire . pdf . security . pdf certificate;
Import? com . spire . pdf . security . pdf certification flags;
Import? com . spire . pdf . security . pdf signature;
Import? Java . awt . *;
Import? Java . awt . geom . point 2d;
Import? Java . awt . geom . rectangle 2d;
Public? Class? Add certificate? {
Public? Static electricity Invalid? main(String[]args){
//load PDF document
PdfDocument? Doctor. =? New? pdf document();
doc . loadfromfile(" test . pdf ");
//Load the pfx certificate and certificate key.
PdfCertificate? Certificate? =? New? PdfCertificate("Cermia.pfx "," 123654yes!" );
//Add a digital signature to the specified page and set its location and size.
PdfSignature? Signature? =? New? PdfSignature(doc,doc.getPages()。 get(2),? Certificate? "My signature");
Rectangle2D? rect? =? New? Rectangular 2D. float();
Rect.setFrame (new? Point 2D Floating ((floating)? doc.getPages()。 Get (0). getActualSize()。 getWidth()? -? 340,? (floating)? doc.getPages()。 Get (0). getActualSize()。 getHeight()? -? 230),? New? Dimension (280,? 150));
signature . set bounds(rect);
//Set the signature to picture plus text mode.
signature . setgraphicmode(GraphicMode。 Logo _ image _ and _ logo _ details);
//Set the content of the signature
signature . setname label(" signer:");
signature . setname(" Mia ");
signature . setcontactinfolabel(" Tel:");
signature . setcontactinfo(" 0288 1705 109 ");
signature . set date label(" date:");
Signature.setDate (new? Java . util . date());
signature . setlocationinfolabel(" location:");
Signature.setLocationInfo ("Chengdu");
signature . setreasonlabel(" reason:");
Signature.setReason ("document owner");
signature . setdistinguishednamelabel(" DN:");
signature . setdistinguishedname(signature . get certificate()。 get_IssuerName()。 getName());
signature . setsignimagesource(pdf image . from file(" sign . png "));
//Set the font of the signature
Signature.setSignDetailsFont (new? PdfTrueTypeFont (new? Font ("Arial? Unicode? ",,lady? Font. Flat and faint? 9)));
//Set document permissions to prevent changes.
signature . setdocumentpermissions(PdfCertificationFlags。 Prohibit _ change);
signature . set certified(true);
//Save the document
doc . savetofile(" add signature . pdf ");
doc . close();
}
} Digital signature adding effect:
Digital signature effect
Refer to the original text