Example usage for com.lowagie.text.pdf PdfArray remove

List of usage examples for com.lowagie.text.pdf PdfArray remove

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfArray remove.

Prototype

public PdfObject remove(int idx) 

Source Link

Document

Remove the element at the specified position from the array.

Usage

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  o m*/
    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();
}