List of usage examples for com.lowagie.text.pdf PdfName DA
PdfName DA
To view the source code for com.lowagie.text.pdf PdfName DA.
Click Source Link
From source file:org.opensignature.opensignpdf.PDFSigner.java
License:Open Source License
/** * /*from w w w . j a v a 2 s . com*/ * @param pdfFile * @return * @throws IOException * @throws DocumentException * @throws FileNotFoundException */ private PdfReader createPDFReader(File pdfFile) throws IOException, DocumentException, FileNotFoundException { logger.info("[createPDFReader.in]:: " + Arrays.asList(new Object[] { pdfFile })); PdfReader reader; if ("true".equals(openOfficeSelected)) { String fileName = pdfFile.getPath(); String tempFileName = fileName + ".temp"; PdfReader documentPDF = new PdfReader(fileName); PdfStamperOSP stamperTemp = new PdfStamperOSP(documentPDF, new FileOutputStream(tempFileName)); AcroFields af = stamperTemp.getAcroFields(); af.setGenerateAppearances(true); PdfDictionary acro = (PdfDictionary) PdfReader .getPdfObject(documentPDF.getCatalog().get(PdfName.ACROFORM)); acro.remove(PdfName.DR); HashMap fields = af.getFields(); String key; for (Iterator it = fields.keySet().iterator(); it.hasNext();) { key = (String) it.next(); int a = af.getFieldType(key); if (a == 4) { ArrayList widgets = af.getFieldItem(key).widgets; PdfDictionary widget = (PdfDictionary) widgets.get(0); widget.put(PdfName.FT, new PdfName("Sig")); widget.remove(PdfName.V); widget.remove(PdfName.DV); widget.remove(PdfName.TU); widget.remove(PdfName.FF); widget.remove(PdfName.DA); widget.remove(PdfName.DR); widget.remove(PdfName.AP); } } stamperTemp.close(); documentPDF.close(); reader = new PdfReader(pdfFile.getPath() + ".temp"); } else { reader = new PdfReader(pdfFile.getPath()); } logger.info("[createPDFReader.retorna]:: "); return reader; }
From source file:questions.forms.GetTextFields.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {/* ww w . j av a 2 s .c o m*/ PrintStream out = new PrintStream(new File(RESULT)); PdfLister lister = new PdfLister(out); PdfReader reader = new PdfReader(RESOURCE); PdfDictionary root = reader.getCatalog(); PdfDictionary acroform = root.getAsDict(PdfName.ACROFORM); out.println("These are the form's font dictionaries:"); PdfDictionary fonts = acroform.getAsDict(PdfName.DR).getAsDict(PdfName.FONT); for (PdfName key : (Set<PdfName>) fonts.getKeys()) { lister.listDict((PdfDictionary) PdfReader.getPdfObject(fonts.get(key))); } out.println("--------------"); out.println("This is the default appearance for the complete form:"); lister.listAnyObject(PdfReader.getPdfObject(acroform.get(PdfName.DA))); out.println("--------------"); AcroFields form = reader.getAcroFields(); Map<String, Item> fields = form.getFields(); Item item; for (String name : fields.keySet()) { out.println(name); if (form.getFieldType(name) == AcroFields.FIELD_TYPE_TEXT) { item = form.getFieldItem(name); PdfDictionary dict = (PdfDictionary) item.getMerged(0); out.println("This is the field's font dictionary:"); fonts = dict.getAsDict(PdfName.DR).getAsDict(PdfName.FONT); for (PdfName key : (Set<PdfName>) fonts.getKeys()) { lister.listDict((PdfDictionary) PdfReader.getPdfObject(fonts.get(key))); } out.println("---"); out.println("This is the field's default appearance"); lister.listAnyObject(PdfReader.getPdfObject(dict.get(PdfName.DA))); } else { out.println("NOT A TEXT FIELD!"); } out.println("--------------"); } } catch (IOException e) { e.printStackTrace(); } }