Hi,
I have read chapter 8 of "iText in Action - Second Edition and I tryed to use 
the iText classes (as show XfaMovie.java)  in in the attached code and with the 
attached file. But so it don't work. What is wrong?

             File samplePDF = new File ("SamplePDF.pdf");
             File sampleXfaPDF = new File ("SampleXfaPDF.pdf");

             ByteArrayOutputStream os = new ByteArrayOutputStream();
        OutputStreamWriter out = new OutputStreamWriter(os, "UTF-8");
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
        out.write("<movies>\n");
        for (int i = 0; i < 4; i++) {
            out.append("\t<title>");
            out.append("Title" + i);
            out.append("</title>\n");
        }
        out.write("</movies>");
        out.flush();
        out.close();

        byte[] xml = os.toByteArray();
        os.close();
             DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
        fact.setNamespaceAware(true);
        DocumentBuilder db = fact.newDocumentBuilder();
        ByteArrayInputStream bais = new ByteArrayInputStream(xml);
        Document doc = db.parse(bais);


       FileInputStream src = new FileInputStream(samplePDF);
       FileOutputStream dest = new FileOutputStream(sampleXfaPDF);

             PdfReader reader = new PdfReader(src);
        PdfStamper stamper = new PdfStamper(reader, dest);
        XfaForm xfa = new XfaForm(reader);
        xfa.setDomDocument(doc);
        xfa.setChanged(true);
        XfaForm.setXfa(xfa, stamper.getReader(), stamper.getWriter());
        stamper.close();

             src = new FileInputStream(sampleXfaPDF);
       reader = new PdfReader(src);
        AcroFields form = reader.getAcroFields();
        xfa = form.getXfa();
        System.out.println(xfa.isXfaPresent() ? "XFA form" : "AcroForm");
        Set<String> fields = form.getFields().keySet();
        for (String key : fields) {
             System.out.println(key);
        }

        Document docResult = xfa.getDomDocument();
             if (docResult != null) {
                    Transformer tf = 
TransformerFactory.newInstance().newTransformer();
               tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
               tf.setOutputProperty(OutputKeys.INDENT, "yes");
               tf.transform(new DOMSource(docResult), new 
StreamResult(System.out));
             } else
                    System.out.println("no document");

The result is:

AcroForm
no document

Thanks & Regards,

Alfonso


Da: 1T3XT BVBA [mailto:[email protected]]
Inviato: giovedì 22 settembre 2011 16:27
A: Post all your questions about iText here
Oggetto: Re: [iText-questions] add xfa:datasets to any PDF file NOT generated 
by LiveCycle Designer

On 22/09/2011 13:05, Massa Alfonso wrote:
Hi,
I have a PDF file NOT generated by LiveCycle Designer and I want add a generic 
XmlDocument to this.
Probably I have to use the XfaForm class.

This is the structure that I expect to find into the resulted PDF file.

<xdp:xdp xmlns="" 
xmlns:xdp="http://ns.adobe.com/xdp/";<http://ns.adobe.com/xdp/>>
<config 
xmlns="http://www.xfa.org/schema/xci/1.0/";<http://www.xfa.org/schema/xci/1.0/> 
xmlns:xfa="http://www.xfa.org/schema/xci/1.0/";<http://www.xfa.org/schema/xci/1.0/>
 />
<template/>
<xfa:datasets 
xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/";<http://www.xfa.org/schema/xfa-data/1.0/>>
<xfa:data>
<Data1/>
<XmlDocument/>
<DataN/>
</xfa:data>
</xfa:datasets>
</xdp:xdp>

How can I do this with java itext?
Someone can help me with a java sample?

Yes, please read chapter 8 of "iText in Action - Second Edition".
It explains how to find the different parts of an XFA form.



________________________________
AVVISO DI RISERVATEZZA
Informazioni riservate possono essere contenute nel messaggio o nei suoi 
allegati. Se non siete i destinatari indicati nel messaggio, o responsabili per 
la sua consegna alla persona, o se avete ricevuto il messaggio per errore, 
siete pregati di non trascriverlo, copiarlo o inviarlo a nessuno. In tal caso 
vi invitiamo a cancellare il messaggio ed i suoi allegati. Grazie.

CONFIDENTIALITY NOTICE
Confidential information may be contained in this message or in its 
attachments. If you are not the addressee indicated in this message, or 
responsible for message delivering to that person, or if you have received this 
message in error, you may not transcribe, copy or deliver this message to 
anyone. In that case, you should delete this message and its attachments. Thank 
you.
------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security
threats, fraudulent activity, and more. Splunk takes this data and makes
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2dcopy2
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to