List of usage examples for com.lowagie.text.pdf PdfDictionary remove
public void remove(PdfName key)
PdfObject
and its key from the PdfDictionary
. From source file:ispyb.common.util.PDFFormFiller.java
License:Open Source License
/** * Render and finalize the PDF form filled with data * //from w w w . ja v a2 s . c o m * @throws Exception */ public void render() throws Exception { // This is mandatory not to have the "Expected a dict object" // message when the result ouput is openned!!! PdfDictionary pdfDictionary = (PdfDictionary) PdfReader .getPdfObject(this.reader.getCatalog().get(PdfName.ACROFORM)); pdfDictionary.remove(new PdfName("XFA")); // /////////////////////////////////////////////////////////// if (this.stamper != null) { this.stamper.setFormFlattening(true); this.stamper.close(); this.stamper = null; } if (this.reader != null) { this.reader.close(); this.reader = null; } if (this.writer != null) { if (!this.writer.isCloseStream()) this.writer.close(); this.writer = null; } this.formFields = null; }
From source file:org.opensignature.opensignpdf.PDFSigner.java
License:Open Source License
/** * /*from w w w. j a v a2 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.RemoveXfa.java
@SuppressWarnings("unchecked") public static void main(String[] args) { try {/*from ww w . j av a 2s . co m*/ PdfReader reader = new PdfReader(RESOURCE); PdfDictionary root = reader.getCatalog(); PdfDictionary acroform = root.getAsDict(PdfName.ACROFORM); acroform.remove(PdfName.XFA); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); AcroFields form = stamper.getAcroFields(); Map<String, Item> fields = form.getFields(); for (String field : fields.keySet()) { System.out.println(field); form.setField(field, "value"); } stamper.partialFormFlattening("topmostSubform[0].Page1[0].SN_NUMBER[0]"); stamper.setFormFlattening(true); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.javascript.RemoveJavaScript.java
public static void main(String[] args) throws DocumentException, IOException { // creating the form with JS AddJavaScriptToForm.main(args);//w w w.jav a2s . com // removing the document level JS PdfReader reader = new PdfReader(AddJavaScriptToForm.RESULT); PdfDictionary root = reader.getCatalog(); PdfDictionary names = root.getAsDict(PdfName.NAMES); names.remove(PdfName.JAVASCRIPT); if (names.size() == 0) { root.remove(PdfName.NAMES); } reader.removeUnusedObjects(); // filling out and flattening the form // (if you don't flatten, you'll get JS errors!) PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); AcroFields form = stamper.getAcroFields(); form.setField("married", "no"); stamper.setFormFlattening(true); stamper.close(); }