List of usage examples for com.lowagie.text.pdf PdfReader removeUnusedObjects
public int removeUnusedObjects()
From source file:org.sejda.impl.itext.component.input.AbstractPdfSourceOpener.java
License:Apache License
public PdfReader open(PdfURLSource source) throws TaskIOException { PdfReader reader; try {// w w w .ja va2s . c o m reader = makeUnethicalIfRequired(openSource(source)); } catch (BadPasswordException bpe) { throw new TaskWrongPasswordException("Unable to open the document due to a wrong password.", bpe); } catch (IOException e) { throw new TaskIOException("An error occurred opening the reader.", e); } reader.removeUnusedObjects(); reader.consolidateNamedDestinations(); return reader; }
From source file:org.sejda.impl.itext.component.input.AbstractPdfSourceOpener.java
License:Apache License
public PdfReader open(PdfFileSource source) throws TaskIOException { PdfReader reader; try {//from w w w. j a v a 2 s . c o m reader = makeUnethicalIfRequired(openSource(source)); } catch (BadPasswordException bpe) { throw new TaskWrongPasswordException("Unable to open the document due to a wrong password.", bpe); } catch (IOException e) { throw new TaskIOException("An error occurred opening the reader.", e); } reader.removeUnusedObjects(); reader.consolidateNamedDestinations(); return reader; }
From source file:org.sejda.impl.itext.component.input.AbstractPdfSourceOpener.java
License:Apache License
public PdfReader open(PdfStreamSource source) throws TaskIOException { PdfReader reader; try {/*from w w w .j a v a 2 s .c o m*/ reader = makeUnethicalIfRequired(openSource(source)); } catch (BadPasswordException bpe) { throw new TaskWrongPasswordException("Unable to open the document due to a wrong password.", bpe); } catch (IOException e) { throw new TaskIOException("An error occurred opening the reader.", e); } reader.removeUnusedObjects(); reader.consolidateNamedDestinations(); return reader; }
From source file:questions.javascript.RemoveJavaScript.java
public static void main(String[] args) throws DocumentException, IOException { // creating the form with JS AddJavaScriptToForm.main(args);//from w w w . j a v a2 s .c om // 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(); }
From source file:questions.stamppages.RemoveAttachmentAnnotations.java
public static void main(String[] args) throws IOException, DocumentException { createPdfWithAttachments();//from ww w . j a v a 2 s . c om PdfReader reader = new PdfReader(RESOURCE); PdfDictionary page; PdfDictionary annotation; for (int i = 1; i <= reader.getNumberOfPages(); i++) { page = reader.getPageN(i); PdfArray annots = page.getAsArray(PdfName.ANNOTS); if (annots != null) { for (int j = annots.size() - 1; j >= 0; j--) { annotation = annots.getAsDict(j); if (PdfName.FILEATTACHMENT.equals(annotation.get(PdfName.SUBTYPE))) { annots.remove(j); } } } } reader.removeUnusedObjects(); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT)); stamper.close(); }