AcroFields { public Map<String, Item> getFields() { return fields; } AcroFields(PdfReader reader, PdfWriter writer); static Object[] splitDAelements(String da); String[] getAppearanceStates(String fieldName); String[] getListOptionExport(String fieldName); String[] getListOptionDisplay(String fieldName); boolean setListOption(String fieldName, String[] exportValues, String[] displayValues); int getFieldType(String fieldName); void exportAsFdf(FdfWriter writer); boolean renameField(String oldName, String newName); void decodeGenericDictionary(PdfDictionary merged, BaseField tx); String getFieldRichValue(String name); String getField(String name); String[] getListSelection(String name); boolean setFieldProperty(String field, String name, Object value, int inst[]); boolean setFieldProperty(String field, String name, int value, int inst[]); void mergeXfaData(Node n); void setFields(FdfReader fdf); boolean regenerateField(String name); boolean setField(String name, String value); boolean setField(String name, String value, boolean saveAppearance); boolean setFieldRichValue(String name, String richValue); boolean setField(String name, String value, String display); boolean setField(String name, String value, String display, boolean saveAppearance); boolean setListSelection(String name, String[] value); Map<String, Item> getFields(); void setFields(XfdfReader xfdf); Item getFieldItem(String name); String getTranslatedFieldName(String name); List<FieldPosition> getFieldPositions(String name); boolean removeFieldsFromPage(int page); boolean removeField(String name, int page); boolean removeField(String name); boolean isGenerateAppearances(); void setGenerateAppearances(boolean generateAppearances); boolean clearSignatureField(String name); ArrayList<String> getSignatureNames(); ArrayList<String> getBlankSignatureNames(); PdfDictionary getSignatureDictionary(String name); PdfIndirectReference getNormalAppearance(String name); boolean signatureCoversWholeDocument(String name); PdfPKCS7 verifySignature(String name); PdfPKCS7 verifySignature(String name, String provider); int getTotalRevisions(); int getRevision(String field); InputStream extractRevision(String field); Map<String, TextField> getFieldCache(); void setFieldCache(Map<String, TextField> fieldCache); void setExtraMargin(float extraMarginLeft, float extraMarginTop); void addSubstitutionFont(BaseFont font); ArrayList<BaseFont> getSubstitutionFonts(); void setSubstitutionFonts(ArrayList<BaseFont> substitutionFonts); XfaForm getXfa(); void removeXfa(); PushbuttonField getNewPushbuttonFromField(String field); PushbuttonField getNewPushbuttonFromField(String field, int order); boolean replacePushbuttonField(String field, PdfFormField button); boolean replacePushbuttonField(String field, PdfFormField button, int order); boolean doesSignatureFieldExist(String name); static final int DA_FONT; static final int DA_SIZE; static final int DA_COLOR; static final int FIELD_TYPE_NONE; static final int FIELD_TYPE_PUSHBUTTON; static final int FIELD_TYPE_CHECKBOX; static final int FIELD_TYPE_RADIOBUTTON; static final int FIELD_TYPE_TEXT; static final int FIELD_TYPE_LIST; static final int FIELD_TYPE_COMBO; static final int FIELD_TYPE_SIGNATURE; }
@Test public void fdfTest() throws Exception { String acroform_pdf = "./src/test/resources/com/itextpdf/text/pdf/AcroFieldsTest/acroform.pdf"; String barcode_jpg = "./src/test/resources/com/itextpdf/text/pdf/AcroFieldsTest/barcode.jpg"; String signature_pdf = "./src/test/resources/com/itextpdf/text/pdf/AcroFieldsTest/signature.pdf"; String outFdf = outFolder + "acroform_fields.fdf"; FileOutputStream fos = new FileOutputStream(outFdf); FdfWriter fdfWriter = new FdfWriter(fos); fdfWriter.setFile(new File(acroform_pdf).getAbsolutePath()); fdfWriter.setFieldAsString("FirstName", "Alexander"); fdfWriter.setFieldAsString("LastName", "Chingarev"); PdfReader signatureReader = new PdfReader(signature_pdf); fdfWriter.setFieldAsTemplate("Signature", fdfWriter.getImportedPage(signatureReader, 1)); Image img = Image.getInstance(barcode_jpg); fdfWriter.setFieldAsImage("Barcode", img); fdfWriter.write(); signatureReader.close(); FdfReader fdfReader = new FdfReader(outFdf); HashMap<String, PdfDictionary> fields = fdfReader.getFields(); PdfDictionary barcode = fields.get("Barcode"); PdfStream n = barcode.getAsDict(PdfName.AP).getAsStream(PdfName.N); Assert.assertNotNull(n); byte[] b = FdfReader.getStreamBytes((PRStream) n); Assert.assertEquals(32, b.length); PdfStream img0 = n.getAsDict(PdfName.RESOURCES).getAsDict(PdfName.XOBJECT).getAsStream(new PdfName("img0")); Assert.assertNotNull(img0); PdfDictionary signature = fields.get("Signature"); n = signature.getAsDict(PdfName.AP).getAsStream(PdfName.N); Assert.assertNotNull(n); b = FdfReader.getStreamBytes((PRStream) n); Assert.assertEquals(24410, b.length); fdfReader.close(); }