Example usage for com.lowagie.text.pdf PdfName JAVASCRIPT

List of usage examples for com.lowagie.text.pdf PdfName JAVASCRIPT

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfName JAVASCRIPT.

Prototype

PdfName JAVASCRIPT

To view the source code for com.lowagie.text.pdf PdfName JAVASCRIPT.

Click Source Link

Document

A name

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);/*w  w  w .j  a va2 s  .  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();
}