Examples of PDAcroForm


Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

        PDFCloneUtility cloner = new PDFCloneUtility(destination);

        try
        {
            PDAcroForm destAcroForm = destCatalog.getAcroForm();
            PDAcroForm srcAcroForm = srcCatalog.getAcroForm();
            if (destAcroForm == null)
            {
                cloner.cloneForNewDocument(srcAcroForm);
                destCatalog.setAcroForm(srcAcroForm);
            }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

        // load the document
        PDDocument pdfDocument = PDDocument
                .loadNonSeq(new File(formTemplate),null);

        // get the document catalog
        PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();
       
        // as there might not be an AcroForm entry a null check is necessary
        if (acroForm != null)
        {
            // Retrieve an individual field and set it's value.
            PDFieldTreeNode field = acroForm.getField( "sampleField" );
            field.setValue("Text Entry");

            // If a field is nested within the form tree a fully qualified name
            // might be provided to access the field.
            field = acroForm.getField( "fieldsContainer.nestedSampleField" );
            field.setValue("Text Entry");
        }

        // Save and close the filled out form.
        pdfDocument.save(filledForm);
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

    public void validate(PreflightContext ctx) throws ValidationException
    {
        PDDocumentCatalog catalog = ctx.getDocument().getDocumentCatalog();
        if (catalog != null)
        {
            PDAcroForm acroForm = catalog.getAcroForm();
            if (acroForm != null)
            {
                checkNeedAppearences(ctx, acroForm);
                try
                {
                    exploreFields(ctx, acroForm.getFields());
                }
                catch (IOException e)
                {
                    throw new ValidationException("Unable to get the list of fields : " + e.getMessage(), e);
                }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

        int startIndex = Math.max(Math.min(options.getPage(), 0), pageCount - 1);
        PDPage page = catalog.getPages().get(startIndex);

        // Get the AcroForm from the Root-Dictionary and append the annotation
        PDAcroForm acroForm = catalog.getAcroForm();
        catalog.getCOSObject().setNeedToBeUpdate(true);

        if (acroForm == null)
        {
            acroForm = new PDAcroForm(this);
            catalog.setAcroForm(acroForm);
        }
        else
        {
            acroForm.getCOSObject().setNeedToBeUpdate(true);
        }

        // For invisible signatures, the annotation has a rectangle array with values [ 0 0 0 0 ]. This annotation is
        // usually attached to the viewed page when the signature is created. Despite not having an appearance, the
        // annotation AP and N dictionaries may be present in some versions of Acrobat. If present, N references the
        // DSBlankXObj (blank) XObject.

        // Create Annotation / Field for signature
        List<PDAnnotation> annotations = page.getAnnotations();

        List<PDFieldTreeNode> fields = acroForm.getFields();
        PDSignatureField signatureField = null;
        if(fields == null)
        {
            fields = new ArrayList<PDFieldTreeNode>();
            acroForm.setFields(fields);
        }
        for (PDFieldTreeNode pdField : fields)
        {
            if (pdField instanceof PDSignatureField)
            {
                PDSignature signature = ((PDSignatureField) pdField).getSignature();
                if (signature != null && signature.getDictionary().equals(sigObject.getDictionary()))
                {
                    signatureField = (PDSignatureField) pdField;
                }
            }
        }
        if (signatureField == null)
        {
            signatureField = new PDSignatureField(acroForm);
            signatureField.setSignature(sigObject); // append the signature object
            signatureField.getWidget().setPage(page); // backward linking
        }

        // Set the AcroForm Fields
        List<PDFieldTreeNode> acroFormFields = acroForm.getFields();
        acroForm.getDictionary().setDirect(true);
        acroForm.setSignaturesExist(true);
        acroForm.setAppendOnly(true);

        boolean checkFields = false;
        for (PDFieldTreeNode field : acroFormFields)
        {
            if (field instanceof PDSignatureField)
            {
                if (((PDSignatureField) field).getCOSObject().equals(signatureField.getCOSObject()))
                {
                    checkFields = true;
                    signatureField.getCOSObject().setNeedToBeUpdate(true);
                    break;
                }
            }
        }
        if (!checkFields)
        {
            acroFormFields.add(signatureField);
        }

        // Get the object from the visual signature
        COSDocument visualSignature = options.getVisualSignature();

        // Distinction of case for visual and non-visual signature
        if (visualSignature == null) // non-visual signature
        {
            // Set rectangle for non-visual signature to 0 0 0 0
            signatureField.getWidget().setRectangle(new PDRectangle()); // rectangle array [ 0 0 0 0 ]
            // Clear AcroForm / Set DefaultRessource
            acroForm.setDefaultResources(null);
            // Set empty Appearance-Dictionary
            PDAppearanceDictionary ap = new PDAppearanceDictionary();

            COSStream apsStream = getDocument().createCOSStream();
            apsStream.createUnfilteredStream();
            PDAppearanceStream aps = new PDAppearanceStream(apsStream);
            COSDictionary cosObject = (COSDictionary) aps.getCOSObject();
            cosObject.setItem(COSName.SUBTYPE, COSName.FORM);
            cosObject.setItem(COSName.BBOX, new PDRectangle());

            ap.setNormalAppearance(aps);
            ap.getCOSObject().setDirect(true);
            signatureField.getWidget().setAppearance(ap);
        }
        else
        // visual signature
        {
            // Obtain visual signature object
            List<COSObject> cosObjects = visualSignature.getObjects();

            boolean annotNotFound = true;
            boolean sigFieldNotFound = true;
            COSDictionary acroFormDict = acroForm.getDictionary();
            for (COSObject cosObject : cosObjects)
            {
                if (!annotNotFound && !sigFieldNotFound)
                {
                    break;
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

            SignatureOptions options) throws IOException
    {
        PDDocumentCatalog catalog = getDocumentCatalog();
        catalog.getCOSObject().setNeedToBeUpdate(true);

        PDAcroForm acroForm = catalog.getAcroForm();
        if (acroForm == null)
        {
            acroForm = new PDAcroForm(this);
            catalog.setAcroForm(acroForm);
        }
        else
        {
            acroForm.getCOSObject().setNeedToBeUpdate(true);
        }

        COSDictionary acroFormDict = acroForm.getDictionary();
        acroFormDict.setDirect(true);
        acroFormDict.setNeedToBeUpdate(true);
        if (!acroForm.isSignaturesExist())
        {
            acroForm.setSignaturesExist(true); // 1 if at least one signature field is available
        }

        List<PDFieldTreeNode> field = acroForm.getFields();

        for (PDSignatureField sigField : sigFields)
        {
            PDSignature sigObject = sigField.getSignature();
            sigField.getCOSObject().setNeedToBeUpdate(true);
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

     * @throws IOException if no document catalog can be found.
     */
    public List<PDSignatureField> getSignatureFields() throws IOException
    {
        List<PDSignatureField> fields = new LinkedList<PDSignatureField>();
        PDAcroForm acroForm = getDocumentCatalog().getAcroForm();
        if (acroForm != null)
        {
            List<COSDictionary> signatureDictionary = document.getSignatureFields(false);
            for (COSDictionary dict : signatureDictionary)
            {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

     * @throws IOException If there is an error setting the field.
     */
    public void setField(PDDocument pdfDocument, String name, String value) throws IOException
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        PDFieldTreeNode field = acroForm.getField(name);
        if (field != null)
        {
            field.setValue(value);
        }
        else
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

     * @throws IOException If there is an error getting the fields.
     */
    public void printFields(PDDocument pdfDocument) throws IOException
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        List<PDFieldTreeNode> fields = acroForm.getFields();
        Iterator<PDFieldTreeNode> fieldsIter = fields.iterator();

        System.out.println(new Integer(fields.size()).toString() + " top-level fields were found on the form");

        while (fieldsIter.hasNext())
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

        {
            PDDocument fdeb = null;
            try
            {
                fdeb = PDDocument.load( filePDF );
                PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm();
                PDTextField field = (PDTextField)form.getField( "f67_1" );
                field.setValue( "2" );
   
                String expected =
                    "/Tx BMC " +
                    "BT " +
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.interactive.form.PDAcroForm

        {
            PDDocument fdeb = null;
            try
            {
                fdeb = PDDocument.load( filePDF );
                PDAcroForm form = fdeb.getDocumentCatalog().getAcroForm();
                PDTextField feld2 = (PDTextField)form.getField( "Feld.2" );
                feld2.setValue( "Benjamin" );
   
                String expected =
                "1 1 0.8000000119 rg " +
                " 0 0 127.5 19.8299999237 re " +
                " f " +
                " 0 0 0 RG " +
                " 1 w " +
                " 0.5 0.5 126.5 18.8299999237 re " +
                " S " +
                " 0.5 g " +
                " 1 1 m " +
                " 1 18.8299999237 l " +
                " 126.5 18.8299999237 l " +
                " 125.5 17.8299999237 l " +
                " 2 17.8299999237 l " +
                " 2 2 l " +
                " 1 1 l " +
                " f " +
                " 0.75 g " +
                " 1 1 m " +
                " 126.5 1 l " +
                " 126.5 18.8299999237 l " +
                " 125.5 17.8299999237 l " +
                " 125.5 2 l " +
                " 2 2 l " +
                " 1 1 l " +
                " f " +
                " /Tx BMC  " +
                "BT " +
                "/Helv 14 Tf " +
                " 0 0 0 rg " +
                " 4 4.721 Td " +
                "(Benjamin) Tj " +
                "ET " +
                "EMC";
   
                testContentStreams( fdeb, feld2, expected );
   
                PDRadioButton feld3 = (PDRadioButton)form.getField( "Feld.3" );
                feld3.setValue("RB1");
                assertEquals( "RB1", feld3.getValue().getName() );
            }
            finally
            {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.