Example usage for com.lowagie.text.pdf PdfReader getCatalog

List of usage examples for com.lowagie.text.pdf PdfReader getCatalog

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfReader getCatalog.

Prototype

public PdfDictionary getCatalog() 

Source Link

Document

Returns the document's catalog.

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  ww  w .  j a  v  a  2 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();
}

From source file:questions.metadata.ReplaceXMP.java

public static void alterXmp1() {
    try {//from   ww  w  .  jav a  2s  . c  o m
        PdfReader reader = new PdfReader(ORIGINAL);
        PdfDictionary catalog = reader.getCatalog();
        PdfObject obj = catalog.get(PdfName.METADATA);
        PRStream stream = (PRStream) PdfReader.getPdfObject(obj);
        String metadata = new String(PdfReader.getStreamBytes(stream));
        metadata = metadata.replaceAll("Hello World", "Hello Universe");
        stream.setData(metadata.getBytes(), false);
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT1));
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    }
}