Expand my Community achievements bar.

Step by step instruction to create dynamic table (record inserts) via XML feed (using XPAAJ.JAR)

Avatar

Former Community Member
Have searched this forum, found very helpful tips, however, I have not found a thread detailing exactly what we need to do to allow a PDF created with Lifecycle and accessed by the Adobe Java to PDF API XPAAJ.JAR to be able to dynamically insert rows via an XML feed.<br /><br />This is what I have done so far:<br /><br />Using the Adobe XPAAJ.JAR Java to PDF API I have wrote a Java program that successfuly inserts data on a 1:1 ratio (XML element to PDF field). <br /><br />My XML file has this schema:<br />**********************************************<br />**********************************************<br /><?xml version="1.0"?><br /><br /><xs:schema xmlns:xs="http://www.xyz.com" <br />targetNamespace="http://www.xyz.com" <br />xmlns="http://www.xyz.com" <br />elementFormDefault="qualified"><br /><br /><xs:element name="num" type="xs:string"/><br /><xs:element name="revdate" type="xs:string"/><br /><xs:element name="policy" type="xs:string"/><br /><xs:element name="copy" type="xs:string"/><br /><xs:element name="insured" type="xs:string"/><br /><xs:element name="member" type="xs:string"/><br /><xs:element name="cert" type="xs:string"/><br /><xs:element name="eff_date" type="xs:string"/><br /><xs:element name="iss_date" type="xs:string"/><br /><br /><xs:element name="record" maxOccurs="unbounded"><br /> <xs:complexType><br /> <xs:sequence><br /> <xs:element name="temp_phy" type="xs:string"/><br /> <xs:element name="cov_type" type="xs:string"/><br /> <xs:element name="dates" type="xs:string"/><br /> </xs:sequence><br /> </xs:complexType><br /></xs:element><br /></xs:schema><br />************************************<br />************************************<br /><br />My XML data feed looks like this:<br />************************************<br />************************************<br /><?xml version="1.0" encoding="ISO-8859-1"?><br /><br /><endorsement xmlns="http://www.xyz.com" <br />xmlns:xsi="http://www.xyz.com" <br />xsi:schemaLocation="sampleschema.xsd"><br /><br /><num>123456</num><br /><revdate>09/03</revdate><br /><policy>0000123456</policy><br /><copy></copy><br /><insured>ABC GROUP</insured><br /><member></member><br /><cert></cert><br /><eff_date>05/24/2007, 12:01 A.M. Standard Time</eff_date><br /><iss_date>06/12/2007</iss_date><br /><br /><record><br /> <temp_phy>John Doe MD</temp_phy><br /> <cov_type>ALT</cov_type><br /> <dates>05/23/07 - 05/24/07</dates><br /></record><br /><record><br /> <temp_phy>Jane Doe MD</temp_phy><br /> <cov_type>ALT</cov_type><br /> <dates>05/24/07 - 05/25/07</dates><br /></record><br /><record><br /> <temp_phy>Jane Pauly MD</temp_phy><br /> <cov_type>ALT</cov_type><br /> <dates>05/25/07 - 05/26/07</dates><br /></record><br /></endorsement><br />***********************************************<br />***********************************************<br /><br />My problem is trying to get the "record" xml elements to be inserted into the PDF (the volume of "record" elements will always change)<br /><br />When I open Lifecycle I have inserted a table and tried to figure out the binding capability, however, I am running into issues on how to both format the table and bind (lbls are appearing on the left, no place to designate field and is binding neccesary with the Java API?)<br /><br />Long story short... If I have a successful PDF with form fields that recieves data via the Java to PDF API. Exactly what do I have to do to the PDF, XML and Schema to allow rows/cols in table like format to be inserted without knowing how many rows I will need ahead of time. The resulting PDF may be 1 page or 20 pages in length depending the volume of row insertions.<br /><br />Thanks in advance,<br /><br />John
2 Replies

Avatar

Former Community Member
[Follow Up]<br /><br />After a bit of trial and error I figured it out!<br /><br />For those that need help and are new to Lifecycle, perhaps these tips will help. I'm not certain if these tips work in Lifecycle 7.x as I am using Lifecycle 8.x.<br /><br />****<br />NOTE: If you look at the XML and schema above, I changed the tag <record> to <transaction_detail> as far as my tips are concerned below.<br />****<br /><br />Tips if you need to loop through a complex type element XML feed with XPAAJ:<br />1.) Subforms and tables act the same as far as binding. A subform is an object that allows you to tie elements within the boundaries of the subform to XML field binding and PDF form placement rules. Tables act like subforms from a object binding perspective and in fact can also be placed in a subform.<br /><br />2.) Insert a table or subform or both and then drag the subform or table to the parent form on the hierarchy tab. ****The "Pagination" tab and repeat options will be grayed out if you do not place the subform on the same level as the main PDF form.**** I do not think this is true with Lifecycle 7.x, but it appears to be true with Lifecycle 8.x<br /><br />3.) Select the "Repeat ..." option. Be careful to select repeat on the objects that you want repeated. A repeat on a subform will repeat the entire subform! (All objects within the subform will be repeated). If your just after a table with body rows that repeat. My suggestion is to place your table in a subform (this is so you can more easily resize the width of the table, as it appears the width is locked to the Master page width if a table is not placed within a subform). On your table header row within the hierarchy tab, do not select repeat. On the table body row, seek the repeat check box and go over the various options.<br /><br />4.) Save your PDF as "Dynamic...XML PDF" before you run the Java.<br /><br />5.) On the table or subform, name your binding for the parent complex element tag. My complex element is named "transaction_detail" so my main object table bind is named: "transaction_detail." Then under default binding either choose "normal" or in my case "$record.transaction_detail[*]." <-- I have no idea why this "$record.YOURCOMPLEXELEMENTTAG[*]" is not documented better. It appears "$record.xxxx..." is a reference to a XML complex element and the "[*]" refers to the child elements that fall within the parent complex element. So "$record.transaction_detail[*]" as my main table default binding is telling my table that it is tied to the transaction_detail complex element and the colums within the table are represented by the "[*]" wild card. You then need to bind each child element to each respective cell within that table. Use the hierarchy tab to navigate between objects and feel free to drag and drop objects to where they should be.<br /><br />6.) Now for your table header row (if you have one), Name it and then choose "None" for default binding as you will probably not want any dynamic insertions for your colum descriptions. Play around with the options if you need the header row to repeat on over flow pages, etc.<br /><br />7.) Name each cell with the element name that corresponds within your XML and set default bind as either normal or in my case use the same name. "Normal" just means that the bind is to seek out the respective named element within the XML. TextField or Cell named "XYZ" with default binding set to normal will seek element tag "XYZ" within the XML for data insertion. You can of course over write this match by default binding to any XML element name of your choice.<br /><br />8.) If your repeating a subform with textfields, it's the same concept.<br /><br />9.) No need to import a new data connection (schema) if know your schema, it just helps for drag and drop options from the hierarchy tab.<br /><br />Run your java code and voila! It should work. <br /><br />So for those of you wondering if you can use XPAAJ to extract XML data and insert into a PDF dynamically and also incorporate repeating rows of data, yes it can be done!<br /><br />Hope this helps,<br /><br />Thank you,<br /><br />John

Avatar

Former Community Member
Response.ContentType = "application/vnd.adobe.xdp+xml";<br /> strXML = "<?xml version='1.0' encoding='UTF-8'?>";<br /> strXML = strXML + "<?xfa generator='AdobeDesigner_V7.0' APIVersion='2.2.4333.0'?>";<br /> strXML = strXML + "<xdp:xdp xmlns:xdp='http://ns.adobe.com/xdp/'>";<br /> strXML = strXML + "<xfa:datasets xmlns:xfa='http://www.xfa.org/schema/xfa-data/1.0/'>";<br /> strXML = strXML + "<xfa:data>"; <br /> strXML = strXML + "<RepeatForm>"; <br /> strXML = strXML + "<emp>name</emp>"; <br /> strXML = strXML + "</RepeatForm>";<br /> strXML = strXML + "<RepeatForm>";<br /> strXML = strXML + "<emp>name1</emp>";<br /> strXML = strXML + "</RepeatForm>"; <br /> strXML = strXML + "</xfa:data>";<br /> strXML = strXML + "</xfa:datasets>";<br /> strXML = strXML + "<pdf href='http://win-sb-serv/timekeep/Untitled4.pdf' xmlns='http://ns.adobe.com/xdp/pdf/' />";<br /><br /> strXML = strXML + "</xdp:xdp>";<br /> Response.Write(strXML);<br /> Response.Flush();<br /> Response.End(); <br /><br />i have generate above mentioned xml and created a subform named "RepeatForm" and added a textfield named "emp" through adobe livecycle now by xml i m sending more thane one subform as u can see above but the subform is not repeated plz help if is there any other solution.