• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AcroFields类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.itextpdf.text.pdf.AcroFields的典型用法代码示例。如果您正苦于以下问题:Java AcroFields类的具体用法?Java AcroFields怎么用?Java AcroFields使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AcroFields类属于com.itextpdf.text.pdf包,在下文中一共展示了AcroFields类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testRemoveSignatureFromPDFSignedFirmaCerta

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://itext.2136553.n4.nabble.com/trying-to-remove-a-signature-from-pdf-file-tt4660983.html">
 * trying to remove a signature from pdf file
 * </a>
 * <br/>
 * <a href="http://itext.2136553.n4.nabble.com/attachment/4660983/0/PDFSignedFirmaCerta.pdf">
 * PDFSignedFirmaCerta.pdf
 * </a>
 * <p>
 * Indeed, this code fails with a {@link NullPointerException}. The cause is that a dubious construct
 * created by the signature software then is processed by iText code not sufficiently defensively programmed:
 * The signature claims to have an annotation on a page but that page does claim not to have any anotations
 * at all.
 * </p>
 */
@Test
public void testRemoveSignatureFromPDFSignedFirmaCerta() throws IOException, GeneralSecurityException, DocumentException
{
    try (   InputStream inputStream = getClass().getResourceAsStream("PDFSignedFirmaCerta.pdf");
            OutputStream outputStream = new FileOutputStream(new File(RESULT_FOLDER, "PDFSignedFirmaCerta-withoutSig.pdf")))
    {
        Provider provider = new BouncyCastleProvider();
        Security.addProvider(provider);

        PdfReader reader = new PdfReader(inputStream, null);
        AcroFields af = reader.getAcroFields();
        ArrayList<String> names = af.getSignatureNames();
        for (String name : names) {
            System.out.println("Signature name: " + name);
            System.out.println("Signature covers whole document: " + af.signatureCoversWholeDocument(name));
            PdfPKCS7 pk = af.verifySignature(name, provider.getName());
            System.out.println("SignatureDate: " + pk.getSignDate());
            System.out.println("Certificate: " + pk.getSigningCertificate());
            System.out.println("Document modified: " + !pk.verify());
            af.removeField(name);
        }
        PdfStamper stamper = new PdfStamper(reader, outputStream, '\0');
        stamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:41,代码来源:RemoveSignature.java


示例2: numberOfVisibleSignatureFieldsOnSignaturePage

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
private int numberOfVisibleSignatureFieldsOnSignaturePage(AcroFields readerFields, ArrayList<String> signatureFieldsNames, int signaturePage) {
	int count = 0;
	for (String signatureFieldName : signatureFieldsNames) {
		Item i = readerFields.getFieldItem(signatureFieldName);
		int page = i.getPage(0);
		if(page == signaturePage){
			PdfDictionary pdct = i.getMerged(0); 
			PdfNumber flags = pdct.getAsNumber(PdfName.F); 
			if ((flags.intValue() & PdfAnnotation.FLAGS_HIDDEN) == 0) {
				count = count + 1;
			} 
		}
	}
	return count;
}
 
开发者ID:MatheusArleson,项目名称:PdfUtil,代码行数:16,代码来源:PdfSignerV4.java


示例3: testVerifyTestSigned1

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/45027712/invalid-signature-when-signing-an-existing-sigrature-field-with-cosign-sapi">
 * Invalid signature when signing an existing sigrature field with CoSign SAPI
 * </a>
 * <br/>
 * <a href="https://www.dropbox.com/s/j6eme53lleaok13/test_signed.pdf?dl=0">
 * test_signed-1.pdf
 * </a>
 * <p>
 * Validation shows verification success while both Adobe and SD DSS fail.
 * Embedded certificates have issues (emailAddress RDN is typed PrintableString
 * which is wrong - specified is IA5String - and does not even make sense as
 * there is no '@' in PrintableString), but does this explain it?
 * </p>
 */
@Test
public void testVerifyTestSigned1() throws IOException, GeneralSecurityException
{
    System.out.println("\n\ntest_signed-1.pdf\n===================");
    
    try (   InputStream resource = getClass().getResourceAsStream("test_signed-1.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:39,代码来源:VerifySignature.java


示例4: testReadFieldsFromMultiview

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/46730760/no-fields-were-printed-on-console-after-verifying-if-form-is-using-acroform-or-x">
 * No fields were printed on console after verifying if form is using Acroform or XFA technology?
 * </a>
 * <br/>
 * <a href="http://blogs.adobe.com/formfeed/files/formfeed/Samples/multiview.pdf">
 * multiview.pdf
 * </a>
 * from
 * <a href="http://blogs.adobe.com/formfeed/2011/02/multiple-top-level-subforms.html">
 * Multiple Top Level Subforms
 * </a>
 * <p>
 * The OP's observation can be reproduced using this sample PDF.
 * </p>
 */
@Test
public void testReadFieldsFromMultiview() throws IOException {
    try (   InputStream resource = getClass().getResourceAsStream("multiview.pdf")  ) {
        PdfReader reader = new PdfReader(resource);
        AcroFields form = reader.getAcroFields();
        XfaForm xfa = form.getXfa();
        System.out.println(xfa.isXfaPresent() ? "XFA form" : "AcroForm");
        Set<String> fields = form.getFields().keySet();
        for (String key : fields) {
            System.out.println(key);
        }
        System.out.flush();
        System.out.close();
        reader.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:33,代码来源:ShowXfaFields.java


示例5: testVerifySignedOutput

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/37726215/why-does-my-signature-revision-number-increment-by-2-in-itext-after-detached-s">
 * Why does my signature revision number increment by 2 (in itext) after detached signing?
 * </a>
 * <br/>
 * <a href="https://onedrive.live.com/redir?resid=2F03BFDA84B77A41!113&authkey=!ABPGZ7pxuxoE8A0&ithint=file%2Cpdf">
 * signedoutput.pdf
 * </a>
 * <p>
 * The issue cannot be reproduced. In particular the PDF contains only a single revision.
 * </p>
 */
@Test
public void testVerifySignedOutput() throws IOException, GeneralSecurityException
{
    System.out.println("\n\nsignedoutput.pdf\n================");
	
    try (   InputStream resource = getClass().getResourceAsStream("signedoutput.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:36,代码来源:VerifySignature.java


示例6: testVerifyBabyloveSigned

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/42824577/itext-can-not-verify-signed-pdf-docs-edited-by-nitro-pro-10-11">
 * itext can not verify signed pdf docs edited by nitro pro 10/11
 * </a>
 * <br/>
 * <a href="https://alimail.fadada.com/signed.pdf">
 * babylove_signed.pdf
 * </a>
 * <p>
 * Validation correctly shows verification success for a single
 * signature that does cover the whole document.
 * </p>
 */
@Test
public void testVerifyBabyloveSigned() throws IOException, GeneralSecurityException
{
    System.out.println("\n\nbabylove_signed.pdf\n===================");
	
    try (   InputStream resource = getClass().getResourceAsStream("babylove_signed.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:37,代码来源:VerifySignature.java


示例7: testVerifyBabyloveSignedAndModifyByNitro

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/42824577/itext-can-not-verify-signed-pdf-docs-edited-by-nitro-pro-10-11">
 * itext can not verify signed pdf docs edited by nitro pro 10/11
 * </a>
 * <br/>
 * <a href="https://alimail.fadada.com/signed&modify_by_nitro.pdf">
 * babylove_signed&modify_by_nitro.pdf
 * </a>
 * <p>
 * Validation correctly shows verification success for a single
 * signature that does <b>not</b> cover the whole document.
 * </p>
 */
@Test
public void testVerifyBabyloveSignedAndModifyByNitro() throws IOException, GeneralSecurityException
{
    System.out.println("\n\nbabylove_signed&modify_by_nitro.pdf\n===================");
	
    try (   InputStream resource = getClass().getResourceAsStream("babylove_signed&modify_by_nitro.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:37,代码来源:VerifySignature.java


示例8: testVerifyTestDsp

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/46346144/digital-signature-verification-with-itext-not-working">
 * Digital Signature Verification with itext not working
 * </a>
 * <br/>
 * <a href="https://drive.google.com/open?id=0B1XKjvoeoyPZWnk5bzc5T3VSQUk">
 * test_dsp.pdf
 * </a>
 * <p>
 * The issue is that the signature uses ECDSA and iText 5 does not (yet)
 * support ECDSA. "Support" here actually means that iText cannot find
 * the name ECDSA for the OID 1.2.840.10045.4.3.2 (SHA256withECDSA) to
 * build a proper algorithm name to use for verification.
 * </p>
 * <p>
 * Adding a mapping "1.2.840.10045.4.3.2" to "ECDSA" resolves the issue.
 * </p>
 * @see #testVerify20180115an_signed_original()
 */
@Test
public void testVerifyTestDsp() throws IOException, GeneralSecurityException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
    Field algorithmNamesField = EncryptionAlgorithms.class.getDeclaredField("algorithmNames");
    algorithmNamesField.setAccessible(true);
    @SuppressWarnings("unchecked")
    HashMap<String, String> algorithmNames = (HashMap<String, String>) algorithmNamesField.get(null);
    algorithmNames.put("1.2.840.10045.4.3.2", "ECDSA");

    System.out.println("\n\ntest_dsp.pdf\n===================");
    
    try (   InputStream resource = getClass().getResourceAsStream("test_dsp.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:49,代码来源:VerifySignature.java


示例9: testVerifyPdfSampleSigned

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/48285453/verifying-certificate-of-signed-and-secured-pdf-in-itext-pdf-java">
 * Verifying certificate of signed and secured PDF in iText PDF Java
 * </a>
 * <br/>
 * <a href="https://drive.google.com/drive/folders/1KAqHUh-Iij0I4WXJUCx-rMd8FQFq5tCe?usp=sharing">
 * pdf-sample-signed.pdf
 * </a>
 * <p>
 * The PDF is both signed and encrypted. Apparently iText "decrypts" the
 * values of the <b>Contents</b> key in signature dictionaries even though
 * this is an explicit exception. The parsing of this "decrypted" signature
 * container obviously fails.
 * </p>
 */
@Test
public void testVerifyPdfSampleSigned() throws IOException, GeneralSecurityException
{
    System.out.println("\n\npdf-sample-signed.pdf\n===================");
    
    try (   InputStream resource = getClass().getResourceAsStream("pdf-sample-signed.pdf") )
    {
        PdfReader reader = new PdfReader(resource, "password".getBytes());
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:39,代码来源:VerifySignature.java


示例10: testDocumentTimestampLikeRadekKantor

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="https://stackoverflow.com/questions/48211757/itext-pdf-timestamp-validation-returns-false-why">
 * iText pdf timestamp validation returns false, why?
 * </a>
 * <br/>
 * <a href="https://drive.google.com/file/d/1skI3NM9cqw2m6eW9jKXaJXKzvCjyQMib/view">
 * testpdf_timestamp.pdf
 * </a>
 * <p>
 * The code the OP used for inspiration was for retrieving information
 * from a signature which may include a signature time stamp. The PDF
 * of the OP, on the other hand, contains a document time stamp. The
 * call `pkcs7.verifyTimestampImprint()` checks the time stamp as a
 * signature time stamp and, therefore, fails.
 * </p>
 */
@Test
public void testDocumentTimestampLikeRadekKantor() throws IOException, GeneralSecurityException {
    try (   InputStream resource = getClass().getResourceAsStream("testpdf_timestamp.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields fields = reader.getAcroFields();
        ArrayList<String> names = fields.getSignatureNames();
        for (String name : names) {
            System.out.println("===== " + name + " =====");
            System.out.println("Signature covers whole document: " + fields.signatureCoversWholeDocument(name));
            System.out.println("Document revision: " + fields.getRevision(name) + " of " + fields.getTotalRevisions());
            PdfPKCS7 pkcs7 = fields.verifySignature(name);
            System.out.println("Integrity check OK? " + pkcs7.verify());
            SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
            System.out.println("Signed on: " + date_format.format(pkcs7.getSignDate().getTime()));
            if (pkcs7.getTimeStampDate() != null) {
                System.out.println("TimeStamp: " + date_format.format(pkcs7.getTimeStampDate().getTime()));
                TimeStampToken ts = pkcs7.getTimeStampToken();
                System.out.println("TimeStamp service: " + ts.getTimeStampInfo().getTsa());
                // Why pkcs7.verifyTimestampImprint() returns FLASE?
                System.out.println("Timestamp verified? " + pkcs7.verifyTimestampImprint());
            }
        }
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:42,代码来源:VerifyTimestamp.java


示例11: addImage

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
public static void addImage(byte[] input, OutputStream output, Image image, String placeholder)
  throws IOException, DocumentException {
  try (PdfReaderAutoclosable pdfReader = new PdfReaderAutoclosable(input);
       PdfStamperAutoclosable pdfStamper = new PdfStamperAutoclosable(pdfReader, output)) {
    AcroFields form = pdfStamper.getAcroFields();
    List<AcroFields.FieldPosition> positions = form.getFieldPositions(placeholder);

    positions.forEach(p -> {
      image.scaleToFit(p.position.getWidth(), p.position.getHeight());
      image.setAbsolutePosition(p.position.getLeft() + (p.position.getWidth() - image.getScaledWidth()) / 2,
        p.position.getBottom() + (p.position.getHeight() - image.getScaledHeight()) / 2);
      PdfContentByte cb = pdfStamper.getOverContent(p.page);

      try {
        cb.addImage(image);
      } catch(DocumentException e) {
        throw Throwables.propagate(e);
      }
    });
  }
}
 
开发者ID:obiba,项目名称:mica2,代码行数:22,代码来源:PdfUtils.java


示例12: testPd3100SetVrPr4ToNo

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/42819618/itext-fill-checkbox-with-value">
 * itext fill checkbox with value
 * </a>
 * <br/>
 * <a href="https://www.poreskaupravars.org/Documents/Doc/PD3100.pdf">
 * PD3100.pdf
 * </a>
 * <p>
 * This test uses a valid name and so at least creates
 * a PDF displayed with a somehow selected field. 
 * </p>
 * @see #testPd3100SetVrPr4ToNoAppend()
 */
@Test
public void testPd3100SetVrPr4ToNo() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("PD3100.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "PD3100-SetVrPr4ToNo.pdf"))  )
    {
        PdfReader pdfReader = new PdfReader(resource);
        PdfStamper pdfStamper = new PdfStamper(pdfReader, result, (char)0, false);
        AcroFields acroFields = pdfStamper.getAcroFields();
        System.out.println("Available values for VrPr4: " + Arrays.asList(acroFields.getAppearanceStates("VrPr4")));
        acroFields.setField("VrPr4", "No");
        pdfStamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:29,代码来源:SetCheckBox.java


示例13: testShowPdfExampleStates

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/39450688/itext-pdf-checkboxon-off-not-appearing-for-some-pdf">
 * IText Pdf - Checkbox(On/Off) not appearing for some pdf
 * </a>
 * <br/>
 * <a href="http://www.filedropper.com/pdfexample_1">
 * PDF example.pdf
 * </a>
 * <p>
 * The observations of the OP cannot be reproduced.
 * </p>
 */
@Test
public void testShowPdfExampleStates() throws IOException
{
    String resourceName = "PDF example.pdf";
    try (   InputStream resource = getClass().getResourceAsStream(resourceName)    )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields form = reader.getAcroFields();
        String[] values = form.getAppearanceStates("claimsType");
        System.out.printf("\n%s\nThe appearance states of claimsType are %s.\n", resourceName, Arrays.asList(values));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:25,代码来源:ShowStates.java


示例14: testShowPdfTest2States

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/39450688/itext-pdf-checkboxon-off-not-appearing-for-some-pdf">
 * IText Pdf - Checkbox(On/Off) not appearing for some pdf
 * </a>
 * <br/>
 * <a href="http://www.filedropper.com/pdftest2">
 * PDF test 2.pdf
 * </a>
 * <p>
 * The observations of the OP cannot be reproduced.
 * </p>
 */
@Test
public void testShowPdfTest2States() throws IOException
{
    String resourceName = "PDF test 2.pdf";
    try (   InputStream resource = getClass().getResourceAsStream(resourceName)    )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields form = reader.getAcroFields();
        String[] values = form.getAppearanceStates("claimsType");
        System.out.printf("\n%s\nThe appearance states of claimsType are %s.\n", resourceName, Arrays.asList(values));
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:25,代码来源:ShowStates.java


示例15: testFillInForm

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
     * <a href="http://stackoverflow.com/questions/28967737/itextsharp-setfield-for-fields-with-same-name-on-different-pages">
     * iTextSharp SetField for fields with same name on different pages
     * </a>
     * <p>
     * Reproducing the issue with iText
     * </p>
     */
    @Test
    public void testFillInForm() throws IOException, DocumentException
    {
        try (   InputStream resource = getClass().getResourceAsStream("ING_bewindvoering_regelen_tcm162-49609.pdf");
                OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "hybrid-form-fillin.pdf"))   )
        {
            PdfReader reader = new PdfReader(resource);
            PdfStamper stamper = new PdfStamper(reader, result);
            AcroFields fields = stamper.getAcroFields();
            fields.setField("topmostSubform[0].CheckBox2A[0]", "1");
//            fields.setField("topmostSubform[0].Page2[0].CheckBox2A[0]", "1");
            stamper.close();
        }
    }
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:23,代码来源:DuplicateHybridFormNames.java


示例16: setFields

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
void setFields(File result, String value) throws IOException, DocumentException
{
    try ( InputStream resource = getClass().getResourceAsStream("RichTextDoc.pdf")  )
    {
        PdfReader reader = new PdfReader(resource);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(result));
        
        AcroFields fields = stamper.getAcroFields();
        fields.setGenerateAppearances(false);
        Assert.assertFalse("Setting rich text to normal field should fail", fields.setFieldRichValue("NormalText", value));
        Assert.assertTrue("Setting rich text to rich text field should succeed", fields.setFieldRichValue("RichText", value));
        
        stamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:16,代码来源:SetRichTextFields.java


示例17: testChangeAppearances

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/37027579/how-to-associate-a-previous-signature-in-a-new-signature-field">
 * How to associate a previous signature in a new signature field
 * </a>
 * <br/>
 * <span>BLANK-signed.pdf, <em>a blank file from elsewhere with an invisible signature.</em></span>
 * <p>
 * Quite surprisingly it turns out that changing the signature appearance is possible without
 * breaking the signature, merely a warning appears which can be hidden by simply signing again.
 * </p>
 */
@Test
public void testChangeAppearances() throws IOException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("BLANK-signed.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "BLANK-signed-app.pdf")))
    {
        PdfReader pdfReader = new PdfReader(resource);
        PdfStamper pdfStamper = new PdfStamper(pdfReader, result, '\0', true);

        AcroFields acroFields = pdfStamper.getAcroFields();
        for (String signatureName : acroFields.getSignatureNames())
        {
            Item field = acroFields.getFieldItem(signatureName);
            field.writeToAll(PdfName.RECT, new PdfArray(new int[]{100,100,200,200}), Item.WRITE_WIDGET);
            field.markUsed(acroFields, Item.WRITE_WIDGET);
            
            PdfAppearance appearance = PdfAppearance.createAppearance(pdfStamper.getWriter(), 100, 100);
            appearance.setColorStroke(BaseColor.RED);
            appearance.moveTo(0, 0);
            appearance.lineTo(99, 99);
            appearance.moveTo(0, 99);
            appearance.lineTo(99, 0);
            appearance.stroke();
            
            PdfDictionary appDict = new PdfDictionary();
            appDict.put(PdfName.N, appearance.getIndirectReference());
            field.writeToAll(PdfName.AP, appDict, Item.WRITE_WIDGET);
        }

        pdfStamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:44,代码来源:ChangeSignatureAppearance.java


示例18: testVerify20180115an_signed_original

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="https://github.com/itext/itextpdf/pull/36">
 * Adding Support for OID 1.2.840.113549.1.1.10 #36
 * </a>
 * <br/>
 * <a href="https://github.com/itext/itextpdf/files/1641593/2018.01.15.an_signed_original.pdf">
 * 2018.01.15.an_signed_original.pdf
 * </a>
 * <p>
 * Support for RSASSA-PSS can also be injected using reflection as done here. 
 * </p>
 * @see #testVerifyTestDsp()
 */
@Test
public void testVerify20180115an_signed_original() throws IOException, GeneralSecurityException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException
{
    Field algorithmNamesField = EncryptionAlgorithms.class.getDeclaredField("algorithmNames");
    algorithmNamesField.setAccessible(true);
    @SuppressWarnings("unchecked")
    HashMap<String, String> algorithmNames = (HashMap<String, String>) algorithmNamesField.get(null);
    algorithmNames.put("1.2.840.113549.1.1.10", "RSAandMGF1");

    System.out.println("\n\n2018.01.15.an_signed_original.pdf\n===================");
    
    try (   InputStream resource = getClass().getResourceAsStream("2018.01.15.an_signed_original.pdf") )
    {
        PdfReader reader = new PdfReader(resource);
        AcroFields acroFields = reader.getAcroFields();

        List<String> names = acroFields.getSignatureNames();
        for (String name : names) {
           System.out.println("Signature name: " + name);
           System.out.println("Signature covers whole document: " + acroFields.signatureCoversWholeDocument(name));
           System.out.println("Document revision: " + acroFields.getRevision(name) + " of " + acroFields.getTotalRevisions());
           PdfPKCS7 pk = acroFields.verifySignature(name);
           System.out.println("Subject: " + CertificateInfo.getSubjectFields(pk.getSigningCertificate()));
           System.out.println("Document verifies: " + pk.verify());
        }
    }

    System.out.println();
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:43,代码来源:VerifySignature.java


示例19: testDA3161_Template

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
/**
 * <a href="http://stackoverflow.com/questions/32332490/new-signature-field-rotated-90-degrees">
 * New Signature Field Rotated 90 Degrees
 * </a>
 * <br/>
 * <a href="https://drive.google.com/open?id=0B3pKBz-WDrXnM3hYeDFtXzhldnM">
 * DA3161-Template.pdf
 * </a>
 * <p>
 * The page in your document is rotated using the Rotate page dictionary entry.
 * When creating a field to be filled-in by others later, you have to add a hint
 * to the field indicating a counter-rotation if you want the field content to
 * effectively appear upright.
 * </p>
 * <p>
 * You do this by setting the MKRotation attribute of the field. This creates a
 * rotation entry R with value 90 in the appearance characteristics dictionary
 * MK of the field.
 * </p>
 */
@Test
public void testDA3161_Template() throws IOException, GeneralSecurityException, NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, DocumentException
{
    try (   InputStream resource = getClass().getResourceAsStream("DA3161-Template.pdf");
            OutputStream result = new FileOutputStream(new File(RESULT_FOLDER, "DA3161-Template_Field.pdf"))    )
    {
        System.out.println("DA3161-Template.pdf");
        PdfReader reader = new PdfReader(resource);
        PdfStamper pdfStamper = new PdfStamper(reader, result);
        AcroFields fields = pdfStamper.getAcroFields();
        int itemno = 3;

      //Get location to the field where we will place the signature field
        FieldPosition NewPosition = fields.getFieldPositions("DESC_0_" + (itemno + 1)).get(0);
        float l1 = NewPosition.position.getLeft();
        float r1 = NewPosition.position.getRight();
        float t1 = NewPosition.position.getTop();
        float b1 = NewPosition.position.getBottom();

        PdfFormField field = PdfFormField.createSignature(pdfStamper.getWriter());
        field.setFieldName("G4_SignatureX");

        // Set the widget properties
        field.setWidget(new Rectangle(r1, t1, l1, b1), PdfAnnotation.HIGHLIGHT_NONE);
        field.setFlags(PdfAnnotation.FLAGS_PRINT);

        // !!!!!!!!!!!!!!!!!!!
        field.setMKRotation(90);

        // Add the annotation
        pdfStamper.addAnnotation(field, 1);

        pdfStamper.close();
    }
}
 
开发者ID:mkl-public,项目名称:testarea-itext5,代码行数:56,代码来源:CreateEmptyField.java


示例20: fillOutForm

import com.itextpdf.text.pdf.AcroFields; //导入依赖的package包/类
public static void fillOutForm(byte[] input, OutputStream output, Map<String, Object> values)
  throws IOException, DocumentException {
  try (PdfReaderAutoclosable pdfReader = new PdfReaderAutoclosable(input);
       PdfStamperAutoclosable stamper = new PdfStamperAutoclosable(pdfReader, output)) {
    stamper.setFormFlattening(true);

    AcroFields fields = stamper.getAcroFields();

    values.forEach((k, v) -> {
      if(v instanceof Boolean) setField(fields, k, (Boolean) v);
      else setField(fields, k, v);
    });
  }
}
 
开发者ID:obiba,项目名称:mica2,代码行数:15,代码来源:PdfUtils.java



注:本文中的com.itextpdf.text.pdf.AcroFields类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java X509DigestResolver类代码示例发布时间:2022-05-22
下一篇:
Java Cookie类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap