Hi out there!

Ok, here is some Code:

I read an XML-File containing the configuration. Next the form ist
filled. The file is reopened and added to a complete file. I don't post 
the attachments yet, as they are to large, I try to make smaller ones 
tomorrow.

         def prueflinge = new groovy.util.XmlParser().parse(new
File(dest, "data.xml"));
         Document d = new Document();
         PdfCopy writer = new PdfCopy(d, new FileOutputStream(new
File(dest, "complete.pdf")));
         d.open();

         prueflinge.pruefling.each{ pling ->
             def bid = pling.berufsid.text();
             def zzos =
prueflinge.zeugniszuordnungen.zeugniszuordnung.findAll {
                 it['@berufsid'] == bid
             };
             def c = 0;
             zzos.each{ zzo ->
                 PdfReader reader = new PdfReader(new FileInputStream(new
File(source, zzo['@zeugnis'])));
                 File act = new File(dest, pling.vorname.text()
                                         + " " + pling.name.text()
                                         + ", " +
pling.ausbildungsnummer.text()
                                         + ", " + pling['@id']
                                         + " - " + c++ + ".pdf");
                 PdfStamper stamp = new PdfStamper(reader,
                     new FileOutputStream(act));
                 AcroFields form = stamp.getAcroFields();
                 XfaForm xfa = form.getXfa();
                 xfa.getDatasetsSom().getOrder().each {name ->
                     def node = xfa.findDatasetsNode(name);
                     if (name.contains("beruf")){
                         if (node.getNodeName() == "p") {
                             xfa.setNodeText(node,
getBerufsText(list.item(0).getTextContent()
                                 , pling.berufsbezeichnung.text()
                                 , pling.fachrichtungart.text()
                                 , pling.fachrichtungsbezeichnung.text()));
                         } else if (node.getParentNode() != null) {
                             def list = 
node.getParentNode().getChildNodes();
                             node.getParentNode().replaceChild(
                                 node.getOwnerDocument().createTextNode(

getBerufsText(list.item(0).getTextContent()
                                         , pling.berufsbezeichnung.text()
                                         , pling.fachrichtungart.text()
                                         ,
pling.fachrichtungsbezeichnung.text())),
                                 list.item(0));
                        }
                     } else if (name.contains("name")){
                         xfa.setNodeText(node, pling.vorname.text()
                                                 + " " + pling.name.text());
                     } else if (name.contains("geburtsdatum")){
                         xfa.setNodeText(node, pling.geburtsdatum.text());
                     } else if (name.contains("ortdatum")){
                         if (pling.pruefungsort.text() != "") {
                             xfa.setNodeText(node, pling.pruefungsort.text()
                                                      + ", den " +
pling.pruefungsdatum.text());
                         } else {
                             xfa.setNodeText(node, "");
                         }
                     } else if (node.getNodeName().matches("t[0-9\\-]*")){
                         def path = node.getNodeName();
                         path = path.substring(1,path.size());
                         def erg = pling.ergebnis.pruefungsergebnis[0];
                         path.split("-").each { pos ->
                             if (pos.size() > 0 && erg != null) {
                                 erg = erg.pruefungsergebnis.find{ el ->
                                     el['@reihenfolge'] == pos;
                                 }
                              }
                         }
                         if (erg != null) {
                             xfa.setNodeText(node, noten[erg['@note']]);
                          }
                     } else {
                         println(name);
                         println(node.getNodeName());
                         println(node.getTextContent());
                         println(node.getParentNode().getNodeName());
                         println(node.getParentNode().getTextContent());
                     }

                 }
                 stamp.close();
                 PdfReader reader2 = new PdfReader(new 
FileInputStream(act));
                 ByteArrayOutputStream baos = new ByteArrayOutputStream();
                 PdfStamper stamp2 = new PdfStamper(reader2, baos);
                 stamp2.setFormFlattening(true);
                 stamp2.close();
                 PdfReader reader3 = new PdfReader(baos.toByteArray());
                 writer.addPage(writer.getImportedPage(reader3, 1));
             }
         }
         d.close();
     }

Thanks, Bernd.
.


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to