Example usage for com.lowagie.text.pdf PdfDictionary size

List of usage examples for com.lowagie.text.pdf PdfDictionary size

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfDictionary size.

Prototype

public int size() 

Source Link

Document

Returns the number of key-value mappings in this PdfDictionary.

Usage

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  a 2s.  c  o  m
    // 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();
}