Example usage for com.lowagie.text.pdf XfaForm setChanged

List of usage examples for com.lowagie.text.pdf XfaForm setChanged

Introduction

In this page you can find the example usage for com.lowagie.text.pdf XfaForm setChanged.

Prototype

public void setChanged(boolean changed) 

Source Link

Document

Sets the changed status of this XFA instance.

Usage

From source file:questions.forms.FillDynamicXfa2.java

public static void main(String[] args) {
    try {//w w w . jav  a2s .  co m
        // getting new data from a "datasets" XML snippet
        File file = new File(RESOURCE_DATA);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document newdoc = db.parse(file);
        Element element = newdoc.getDocumentElement();
        NodeList nodelist = element.getElementsByTagNameNS("http://www.xfa.org/schema/xfa-data/1.0/", "data");
        Node newdata = nodelist.item(0);

        // replacing the XFA in an existing document
        PdfReader reader = new PdfReader(RESOURCE_PDF);
        XfaForm xfa = new XfaForm(reader);
        Document doc = xfa.getDomDocument();
        NodeList list = doc.getElementsByTagNameNS("http://www.xfa.org/schema/xfa-data/1.0/", "datasets");
        list.item(0).replaceChild(doc.importNode(newdata, true), list.item(0).getFirstChild());
        PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(RESULT));
        xfa.setDomDocument(doc);
        xfa.setChanged(true);
        XfaForm.setXfa(xfa, stamper.getReader(), stamper.getWriter());
        stamper.close();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    }
}