Example usage for com.itextpdf.text.pdf XfaForm getDatasetsNode

List of usage examples for com.itextpdf.text.pdf XfaForm getDatasetsNode

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf XfaForm getDatasetsNode.

Prototype

public Node getDatasetsNode() 

Source Link

Document

Gets the Node that corresponds to the datasets part.

Usage

From source file:com.summitthai.view.SubmitionLeaveDocBean.java

private void fileExtractionProcess(UploadedFile uploadFile) throws Exception {
    SubmitionLeaveDocBean.log.info("uploadFile : " + uploadFile);
    XfaForm xfa;
    if (uploadFile != null) {
        if (uploadFile.getInputstream() != null && uploadFile.getInputstream().available() != 0) {
            xfa = extractFormContent(uploadFile.getInputstream());
            SubmitionLeaveDocBean.log/*from   w  w w .  j  ava2 s.  co  m*/
                    .debug("XML of XFA Form = " + DataExtraction.convertXFAToXMLString(xfa.getDatasetsNode()));
            setToLeave(extractNodeContent(xfa));
        }
        SubmitionLeaveDocBean.log.debug("leaveCreate : " + leaveCreate);
    }
}

From source file:com.summitthai.view.SubmitionLeaveDocBean.java

private HashMap<String, String> extractNodeContent(XfaForm xfa) throws Exception {
    HashMap<String, String> hash = new HashMap<String, String>();
    try {//  w  w w . j  a  v a2s  .  co m
        DataExtraction.extractToHashMap(xfa.getDatasetsNode(), hash);
        return hash;
    } finally {
        hash = null;
    }
}

From source file:edu.clemson.lph.pdfgen.PDFUtils.java

License:Open Source License

public static Node getXFADataNode(byte[] pdfDataIn) {
    Node nData = null;//from  ww w.ja  v a 2s  .  c o  m
    try {
        PdfReader reader = new PdfReader(pdfDataIn);
        XfaForm form = new XfaForm(reader);
        Node xmlNode = form.getDatasetsNode();
        if ("xfa:datasets".equals(xmlNode.getNodeName())) {
            nData = xmlNode.getFirstChild();
            if (!"xfa:data".equals(nData.getNodeName())) {
                System.err.println(nData.getNodeName());
                nData = null;
            }
        } else
            System.err.println(xmlNode.getNodeName());
    } catch (IOException e) {
        logger.error(e);
    } catch (ParserConfigurationException e) {
        logger.error(e);
    } catch (SAXException e) {
        logger.error(e);
    }

    return nData;
}

From source file:pdfupdate.PdfUpdate.java

public void readXml(String src, String dest) throws IOException, DocumentException, TransformerException {
    PdfReader reader = new PdfReader(src);
    AcroFields form = reader.getAcroFields();
    XfaForm xfa = form.getXfa();
    Node node = xfa.getDatasetsNode();
    NodeList list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        if ("data".equals(list.item(i).getLocalName())) {
            node = list.item(i);//from w w w  .  j ava  2  s  .co  m
            break;
        }
    }
    list = node.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
        if ("movies".equals(list.item(i).getLocalName())) {
            node = list.item(i);
            break;
        }
    }
    Transformer tf = TransformerFactory.newInstance().newTransformer();
    tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
    tf.setOutputProperty(OutputKeys.INDENT, "yes");
    FileOutputStream os = new FileOutputStream(dest);
    tf.transform(new DOMSource(node), new StreamResult(os));
    reader.close();
}