c# - iTextSharp need to repeat table rows with textfield dynamically -


i reading , filling dynamic pdf template(having dynamic table textfields in each cell) below way using itextsharp [assuming getting single product info source]:

filestream fs = new filestream("c:\\abc\\destinationfile.pdf", filemode.create);  pdfreader reader = new pdfreader("c:\\abc\\sourcetemplatefile.pdf"); pdfstamper stamper = new pdfstamper(reader, fs); xfa = stamper.acrofields.xfa;  string[] strproductlist = productinfo.product.split('|'); string dname= string.format("{0} {1}", strproductlist[0], strproductlist[1]); string labeling = string.format("{0} {1}/{2}", strproductlist[4], strproductlist[2], strproductlist[3]); string did = strproductlist[5]; xfa.setnodetext(xfa.finddatasetsnode("textfield1"), did); xfa.setnodetext(xfa.finddatasetsnode("textfield2"), dname); xfa.setnodetext(xfa.finddatasetsnode("textfield3"), labeling); 

templatefile:

enter image description here

and xfa xml is:

<?xml version="1.0" encoding="utf-8"?> <?xfa generator="adobelivecycledesigner_v11.0.0.20130303.1.892433" apiversion="3.6.13061.0"?> <xdp:xdp xmlns:xdp="http://ns.adobe.com/xdp/" timestamp="2014-12-05t21:49:58z"> <template xmlns="http://www.xfa.org/schema/xfa-template/3.3/">    <?formserver defaultpdfrenderformat acrobat10.0dynamic?>    <subform name="form1" layout="tb" locale="en_in">       <pageset>          <pagearea name="page1" id="page1">             <contentarea x="0.25in" y="0.25in" w="576pt" h="756pt"/>             <medium stock="default" short="612pt" long="792pt"/>             <?templatedesigner expand 1?></pagearea>          <?templatedesigner expand 1?></pageset>       <subform w="576pt" h="756pt">          <subform name="table1" layout="table" columnwidths="61.433mm 66.31mm 60.918mm" x="3.175mm" y="6.35mm">             <border>                <edge/>             </border>             <subform layout="row" name="headerrow" id="headerrow_id">                <assist role="th"/>                <draw h="10mm" name="cell1">                   <border>                      <edge/>                      <corner thickness="0.1778mm"/>                   </border>                   <ui>                      <textedit/>                   </ui>                   <value>                      <text>h1           </text>                   </value>                   <margin topinset="0.5mm" bottominset="0.5mm" leftinset="0.5mm" rightinset="0.5mm"/>                   <para valign="middle" halign="center"/>                   <font typeface="myriad pro"/>                </draw>                <draw h="10mm" name="cell2">                   <border>                      <edge/>                      <corner thickness="0.1778mm"/>                   </border>                   <ui>                      <textedit/>                   </ui>                   <value>                      <text>h2</text>                   </value>                   <margin topinset="0.5mm" bottominset="0.5mm" leftinset="0.5mm" rightinset="0.5mm"/>                   <para valign="middle" halign="center"/>                   <font typeface="myriad pro"/>                </draw>                <draw h="10mm" name="cell3">                   <border>                      <edge/>                      <corner thickness="0.1778mm"/>                   </border>                   <ui>                      <textedit/>                   </ui>                   <value>                      <text>h3</text>                   </value>                   <margin topinset="0.5mm" bottominset="0.5mm" leftinset="0.5mm" rightinset="0.5mm"/>                   <para valign="middle" halign="center"/>                   <font typeface="myriad pro"/>                </draw>                <border>                   <edge presence="hidden"/>                </border>                <occur max="-1"/>                <?templatedesigner expand 1?></subform>             <subform layout="row" name="row1">                <assist role="tr"/>                <field name="textfield1" w="61.433mm" minh="10mm">                   <ui>                      <textedit>                         <border presence="hidden"/>                         <margin/>                      </textedit>                   </ui>                   <font typeface="myriad pro"/>                   <margin topinset="1mm" bottominset="1mm" leftinset="1mm" rightinset="1mm"/>                   <para valign="middle"/>                   <border>                      <edge/>                      <corner thickness="0.1778mm"/>                   </border>                </field>                <field name="textfield2" w="66.31mm" minh="10mm">                   <ui>                      <textedit>                         <border presence="hidden"/>                         <margin/>                      </textedit>                   </ui>                   <font typeface="myriad pro"/>                   <margin topinset="1mm" bottominset="1mm" leftinset="1mm" rightinset="1mm"/>                   <para valign="middle"/>                   <border>                      <edge/>                      <corner thickness="0.1778mm"/>                   </border>                </field>                <field name="textfield3" w="60.918mm" minh="10mm">                   <ui>                      <textedit>                         <border presence="hidden"/>                         <margin/>                      </textedit>                   </ui>                   <font typeface="myriad pro"/>                   <margin topinset="1mm" bottominset="1mm" leftinset="1mm" rightinset="1mm"/>                   <para valign="middle"/>                   <border>                      <edge/>                      <corner thickness="0.1778mm"/>                   </border>                </field>                <border>                   <edge presence="hidden"/>                </border>                <?templatedesigner expand 1?></subform>             <keep intact="contentarea"/>             <overflow leader="headerrow"/>             <?templatedesigner rowpattern first:1, next:1, firstcolor:f0f0f0, nextcolor:ffffff, apply:0?>             <?templatedesigner expand 1?></subform>          <?templatedesigner expand 1?></subform>       <proto/>       <desc>          <text name="version">11.0.0.20130303.1.892433.887364</text>       </desc>       <?templatedesigner expand 1?></subform>    <?templatedesigner defaultpreviewdynamic 1?>    <?templatedesigner defaultrunat client?>    <?templatedesigner grid show:1, snap:1, units:0, color:ff8080, origin:(0,0), interval:(125000,125000)?>    <?templatedesigner defaultcaptionfontsettings face:myriad pro;size:10;weight:normal;style:normal?>    <?templatedesigner defaultvaluefontsettings face:myriad pro;size:10;weight:normal;style:normal?>    <?templatedesigner defaultlanguage javascript?>    <?acrobat javascript strictscoping?>    <?templatedesigner zoom 102?>    <?templatedesigner widoworphancontrol 0?>    <?templatedesigner formtargetversion 33?>    <?templatedesigner rulers horizontal:1, vertical:1, guidelines:1, crosshairs:0?>    <?templatedesigner savetaggedpdf 1?>    <?templatedesigner savepdfwithembeddedfonts 1?></template> <config xmlns="http://www.xfa.org/schema/xci/3.0/">    <agent name="designer">       <!--  [0..n]  -->       <destination>pdf</destination>       <pdf>          <!--  [0..n]  -->          <fontinfo/>       </pdf>    </agent>    <present>       <!--  [0..n]  -->       <pdf>          <!--  [0..n]  -->          <fontinfo/>          <version>1.7</version>          <adobeextensionlevel>8</adobeextensionlevel>       </pdf>       <xdp>          <packets>*</packets>       </xdp>    </present> </config> <localeset xmlns="http://www.xfa.org/schema/xfa-locale-set/2.7/">    <locale name="en_in" desc="english (india)">       <calendarsymbols name="gregorian">          <monthnames>             <month>january</month>             <month>february</month>             <month>march</month>             <month>april</month>             <month>may</month>             <month>june</month>             <month>july</month>             <month>august</month>             <month>september</month>             <month>october</month>             <month>november</month>             <month>december</month>          </monthnames>          <monthnames abbr="1">             <month>jan</month>             <month>feb</month>             <month>mar</month>             <month>apr</month>             <month>may</month>             <month>jun</month>             <month>jul</month>             <month>aug</month>             <month>sep</month>             <month>oct</month>             <month>nov</month>             <month>dec</month>          </monthnames>          <daynames>             <day>sunday</day>             <day>monday</day>             <day>tuesday</day>             <day>wednesday</day>             <day>thursday</day>             <day>friday</day>             <day>saturday</day>          </daynames>          <daynames abbr="1">             <day>sun</day>             <day>mon</day>             <day>tue</day>             <day>wed</day>             <day>thu</day>             <day>fri</day>             <day>sat</day>          </daynames>          <meridiemnames>             <meridiem>am</meridiem>             <meridiem>pm</meridiem>          </meridiemnames>          <eranames>             <era>bc</era>             <era>ad</era>          </eranames>       </calendarsymbols>       <datepatterns>          <datepattern name="full">eeee d mmmm yyyy</datepattern>          <datepattern name="long">d mmmm yyyy</datepattern>          <datepattern name="med">dd-mmm-yy</datepattern>          <datepattern name="short">dd/mm/yy</datepattern>       </datepatterns>       <timepatterns>          <timepattern name="full">h:mm:ss z</timepattern>          <timepattern name="long">h:mm:ss z</timepattern>          <timepattern name="med">h:mm:ss a</timepattern>          <timepattern name="short">h:mm a</timepattern>       </timepatterns>       <datetimesymbols>gymdkhmssedfwwahkzz</datetimesymbols>       <numberpatterns>          <numberpattern name="numeric">z,zz,zz9.zzz</numberpattern>          <numberpattern name="currency">$ z,zz,zz9.99</numberpattern>          <numberpattern name="percent">z,zz,zz9%</numberpattern>       </numberpatterns>       <numbersymbols>          <numbersymbol name="decimal">.</numbersymbol>          <numbersymbol name="grouping">,</numbersymbol>          <numbersymbol name="percent">%</numbersymbol>          <numbersymbol name="minus">-</numbersymbol>          <numbersymbol name="zero">0</numbersymbol>       </numbersymbols>       <currencysymbols>          <currencysymbol name="symbol">rs.</currencysymbol>          <currencysymbol name="isoname">inr</currencysymbol>          <currencysymbol name="decimal">.</currencysymbol>       </currencysymbols>       <typefaces>          <typeface name="myriad pro"/>          <typeface name="minion pro"/>          <typeface name="courier std"/>          <typeface name="adobe pi std"/>          <typeface name="adobe hebrew"/>          <typeface name="adobe arabic"/>          <typeface name="adobe thai"/>          <typeface name="kozuka gothic pro-vi m"/>          <typeface name="kozuka mincho pro-vi r"/>          <typeface name="adobe ming std l"/>          <typeface name="adobe song std l"/>          <typeface name="adobe myungjo std m"/>       </typefaces>    </locale> </localeset> <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="adobe xmp core 5.2-c001 63.139439, 2011/06/07-10:39:26        ">    <rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">       <rdf:description xmlns:xmp="http://ns.adobe.com/xap/1.0/" rdf:about="">          <xmp:metadatadate>2014-12-05t21:49:58z</xmp:metadatadate>          <xmp:creatortool>adobe livecycle designer 11.0</xmp:creatortool>       </rdf:description>       <rdf:description xmlns:pdf="http://ns.adobe.com/pdf/1.3/" rdf:about="">          <pdf:producer>adobe livecycle designer 11.0</pdf:producer>       </rdf:description>       <rdf:description xmlns:desc="http://ns.adobe.com/xfa/promoted-desc/" rdf:about="">          <desc:version rdf:parsetype="resource">             <rdf:value>11.0.0.20130303.1.892433.887364</rdf:value>             <desc:ref>/template/subform[1]</desc:ref>          </desc:version>       </rdf:description>    </rdf:rdf> </x:xmpmeta></xdp:xdp> 

but in cases getting multiple product info source. so, need repeat rows dynamically fill form in "sourcetemplatefile.pdf"

multiple row filling code:

filestream fs = new filestream("c:\\abc\\destinationfile.pdf", filemode.create);          pdfreader reader = new pdfreader("c:\\abc\\sourcetemplatefile.pdf");         pdfstamper stamper = new pdfstamper(reader, fs);         xfa = stamper.acrofields.xfa;          int = 1;         foreach (productinfo n in iwbprods)         {              string[] strproductlist = n.product.split('|');             string dname= string.format("{0} {1}", strproductlist[0], strproductlist[1]);             string labeling = string.format("{0} {1}/{2}", strproductlist[4], strproductlist[2], strproductlist[3]);             string did = strproductlist[5];             xfa.setnodetext(xfa.finddatasetsnode(string.format("textfield{0}", i++)), did);             xfa.setnodetext(xfa.finddatasetsnode(string.format("textfield{0}", i++)), dname);             xfa.setnodetext(xfa.finddatasetsnode(string.format("textfield{0}", i++)), labeling);         } 

so, question how repeat rows dynamically in given pdf temple? if 3 product info source there should 3 rows available fill. or dynamic pdf form filling supported itextsharp?


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -