本文整理汇总了Java中com.itextpdf.text.pdf.PdfSignatureAppearance类的典型用法代码示例。如果您正苦于以下问题:Java PdfSignatureAppearance类的具体用法?Java PdfSignatureAppearance怎么用?Java PdfSignatureAppearance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PdfSignatureAppearance类属于com.itextpdf.text.pdf包,在下文中一共展示了PdfSignatureAppearance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sign50MBruno
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void sign50MBruno() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/50m.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "50m-signedBruno.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, false);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例2: sign50MBrunoAppend
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void sign50MBrunoAppend() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/50m.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "50m-signedBrunoAppend.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例3: sign50MNaive
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/30449348/signing-pdf-memory-consumption">
* Signing PDF - memory consumption
* </a>
* <br>
* <a href="http://50mpdf.tk/50m.pdf">50m.pdf</a>
* <p>
* {@link #sign50MNaive()} tests the naive approach,
* {@link #sign50MBruno()} tests Bruno's original approach,
* {@link #sign50MBrunoPartial()} tests Bruno's approach with partial reading,
* {@link #sign50MBrunoAppend()} tests Bruno's approach with append mode, and
* {@link #sign50MBrunoPartialAppend()} tests Bruno's approach with partial reading and append mode.
* </p>
*/
// runs with -Xmx240m, fails with -Xmx230m
@Test
public void sign50MNaive() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/50m.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "50m-signedNaive.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0');
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例4: sign50MBrunoPartial
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void sign50MBrunoPartial() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/50m.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "50m-signedBrunoPartial.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, false);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例5: sign50MBrunoPartialAppend
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void sign50MBrunoPartialAppend() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/50m.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "50m-signedBrunoPartialAppend.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例6: signCertifyG
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/30526254/sign-concatenated-pdf-in-append-mode-with-certified-no-changes-allowed">
* Sign concatenated PDF in append mode with CERTIFIED_NO_CHANGES_ALLOWED
* </a>
* <br>
* <a href="https://www.dropbox.com/s/lea6r9fup6th44c/test_pdf.zip?dl=0">test_pdf.zip</a>
*
* {@link #signCertifyG()} certifies g.pdf, OK
* {@link #sign2g()} merely signs 2g.pdf, OK
* {@link #signCertify2gNoAppend()} certifies 2g.pdf but not in append mode, OK
* {@link #tidySignCertify2g()} first tidies, then certifies 2g.pdf, OK
* {@link #signCertify2g()} certifies 2g.pdf, Adobe says invalid
* {@link #signCertify2gFix()} certifies 2g-fix.pdf, OK!
*
* 2g-fix.pdf is a patched version of 2g.pdf with a valid /Size trailer entry
* and a valid, single-sectioned cross reference table
*/
@Test
public void signCertifyG() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/g.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "g-certified.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例7: sign2g
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void sign2g() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/2g.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "2g-signed.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
//appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例8: signCertify2g
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void signCertify2g() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/2g.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "2g-certified.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例9: signCertify2gNoAppend
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void signCertify2gNoAppend() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/2g.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "2g-certified-noAppend.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例10: signCertify2gFix
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void signCertify2gFix() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/2g-fix.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "2g-fix-certified.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例11: C2_01_SignHelloWorld_sign
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
public void C2_01_SignHelloWorld_sign(String src, String dest, Certificate[] chain, PrivateKey pk, String digestAlgorithm, String provider, CryptoStandard subfilter, String reason, String location)
throws GeneralSecurityException, IOException, DocumentException {
// Creating the reader and the stamper
PdfReader reader = new PdfReader(src);
FileOutputStream os = new FileOutputStream(dest);
PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0');
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
appearance.setReason(reason);
appearance.setLocation(location);
appearance.setVisibleSignature(new Rectangle(36, 748, 144, 780), 1, "sig");
// Creating the signature
ExternalDigest digest = new BouncyCastleDigest();
ExternalSignature signature = new PrivateKeySignature(pk, digestAlgorithm, provider);
MakeSignature.signDetached(appearance, digest, signature, chain, null, null, null, 0, subfilter);
}
示例12: sign2274_2007_H_PROVISIONAL_multifield
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Test
public void sign2274_2007_H_PROVISIONAL_multifield() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/2274_2007_H_PROVISIONAL - multifield.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "2274_2007_H_PROVISIONAL - multifield-signed.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
//appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature("IntSig1");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例13: signTest_2_user2699460
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
/**
* <a href="http://stackoverflow.com/questions/32818522/itextsharp-setvisiblesignature-not-working-as-expected">
* ITextSharp SetVisibleSignature not working as expected
* </a>
* <p>
* The issue observed by the OP (user2699460) occurs since iText(Sharp) 5.5.7
* both of iText and iTextSharp.
* </p>
* <p>
* The file signed in this sample, test-2-user2699460-signed.pdf, has been created
* as intermediary result using a simplified version of the OP's c# code.
* </p>
*/
@Test
public void signTest_2_user2699460() throws IOException, DocumentException, GeneralSecurityException
{
String filepath = "src/test/resources/mkl/testarea/itext5/signature/test-2-user2699460.pdf";
String digestAlgorithm = "SHA512";
CryptoStandard subfilter = CryptoStandard.CMS;
// Creating the reader and the stamper
PdfReader reader = new PdfReader(filepath, null, true);
FileOutputStream os = new FileOutputStream(new File(RESULT_FOLDER, "test-2-user2699460-signed.pdf"));
PdfStamper stamper =
PdfStamper.createSignature(reader, os, '\0', RESULT_FOLDER, true);
// Creating the appearance
PdfSignatureAppearance appearance = stamper.getSignatureAppearance();
//appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
appearance.setReason("reason");
appearance.setLocation("location");
appearance.setVisibleSignature("Bunker");
// Creating the signature
ExternalSignature pks = new PrivateKeySignature(pk, digestAlgorithm, "BC");
ExternalDigest digest = new BouncyCastleDigest();
MakeSignature.signDetached(appearance, digest, pks, chain,
null, null, null, 0, subfilter);
}
示例14: getServerSigner
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
/**
* @param fullPath
* @param cert
* @param imageBase64
* @return
*/
public static ServerSigner getServerSigner(String fullPath,
Certificate cert, String imageBase64, boolean showSignatureInfo) {
ServerSigner signer = new ServerSigner(fullPath, cert);
signer.setSignatureGraphic(imageBase64);
if(showSignatureInfo) {
signer.setSignatureAppearance(PdfSignatureAppearance.RenderingMode.GRAPHIC_AND_DESCRIPTION);
} else {
signer.setSignatureAppearance(PdfSignatureAppearance.RenderingMode.GRAPHIC);
}
return signer;
}
示例15: signPdf
import com.itextpdf.text.pdf.PdfSignatureAppearance; //导入依赖的package包/类
@Override
public byte[] signPdf(byte[] pdfData, PrivateKey pk, Certificate[] chain, Map<PdfSignatureFields, String> params)
throws DocumentGenerationException {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
PdfReader reader = new PdfReader(pdfData);
PdfStamper pdfStamper = PdfStamper.createSignature(reader, bos, '\0');
PdfSignatureAppearance appearance = pdfStamper.getSignatureAppearance();
for (PdfSignatureFields key : params.keySet()) {
switch (key) {
case LOCATION:
appearance.setLocation(params.get(key));
break;
case REASON:
appearance.setReason(params.get(key));
}
}
appearance.setCertificationLevel(PdfSignatureAppearance.CERTIFIED_NO_CHANGES_ALLOWED);
ExternalDigest digest = new BouncyCastleDigest();
ExternalSignature signature = new PrivateKeySignature(pk, DigestAlgorithms.SHA1, BouncyCastleProvider.PROVIDER_NAME);
MakeSignature.signDetached(appearance, digest, signature, chain, null, null, null, 0, MakeSignature.CryptoStandard.CMS);
pdfStamper.close();
reader.close();
return bos.toByteArray();
} catch (IOException | GeneralSecurityException | DocumentException e) {
throw new DocumentGenerationException(e);
}
}