c# - How can i customize my own P.D.F form using ITextsharper? -


enter image description here

here had enclosed code generate p.d.f document using code can p.d.f stucture want design form here like(salary slip)...

  public void add(int employeenumber, string fromdate, string todate)     {         string pdffilepath = null;         document doc = new document(itextsharp.text.pagesize.letter, 10, 10, 42, 35);         try         {             pdffilepath = server.mappath("~/uploads/bankformedited.pdf");              //string pdffilepath = server.mappath(".") + "/pdf/mypdf.pdf";              //create document class object , set size letter , give space left, right, top, bottom margin             pdfwriter wri = pdfwriter.getinstance(doc, new filestream(pdffilepath, filemode.create));              doc.open();//open document write              font font8 = fontfactory.getfont("arial", 7);              //write content             paragraph paragraph = new paragraph("monday ventures private ltd...");               //this image placing p.d.f screen              //<img src="../images/logo%20175%20x%2040.png">             //string clientlogo = server.mappath("../images/logo%20175%20x%2040.png");             //string imagefilepath = server.mappath("../images/logo%20175%20x%2040.png");             //itextsharp.text.image jpg = itextsharp.text.image.getinstance(imagefilepath);             ////resize image depend upon need               //jpg.scaletofit(80f, 60f);             ////give space before image               //jpg.spacingbefore = 0f;             ////give space after image               //jpg.spacingafter = 1f;             //jpg.alignment = element.header;             //doc.add(jpg);              //datatable dt = getdatatable(employeenumber, fromdate, todate);             datatable dt = new datatable();             dt = getdatatable(employeenumber, fromdate, todate);              if (dt != null)             {                 //craete instance of pdf table , set number of column in table                 pdfptable pdftable = new pdfptable(dt.columns.count);                 pdfpcell pdfpcell = null;                   //add header of pdf table                  pdfpcell = new pdfpcell(new phrase(new chunk("monday ventures private ltd", font8)));                 pdftable.addcell(pdfpcell);                  pdfpcell = new pdfpcell(new phrase(new chunk("id", font8)));                 pdftable.addcell(pdfpcell);                  pdfpcell = new pdfpcell(new phrase(new chunk("dated", font8)));                 pdftable.addcell(pdfpcell);                  pdfpcell = new pdfpcell(new phrase(new chunk("employeeno", font8)));                 pdftable.addcell(pdfpcell);                  pdfpcell = new pdfpcell(new phrase(new chunk("head", font8)));                 pdftable.addcell(pdfpcell);                   pdfpcell = new pdfpcell(new phrase(new chunk("sequence", font8)));                 pdftable.addcell(pdfpcell);                  pdfpcell = new pdfpcell(new phrase(new chunk("added", font8)));                 pdftable.addcell(pdfpcell);                  pdfpcell = new pdfpcell(new phrase(new chunk("substracted", font8)));                 pdftable.addcell(pdfpcell);                  //dated  employeeno head  sequence added substracted                 //how add data datatable pdf table                 (int rows = 0; rows < dt.rows.count; rows++)                 {                     (int column = 0; column < dt.columns.count; column++)                     {                         pdfpcell = new pdfpcell(new phrase(new chunk(dt.rows[rows][column].tostring(), font8)));                         pdftable.addcell(pdfpcell);                     }                 }                  pdftable.spacingbefore = 15f; // give space after text or may overlap table                  doc.add(paragraph);                 doc.add(pdftable);              }           }         catch (documentexception docex)         {          }         catch (ioexception ioex)         {          }         catch (exception ex)         {          }                 {             //doc.close();             //response.write(pdffilepath);             //response.clearcontent();             doc.close();             response.clearheaders();             response.contenttype = "application/pdf";             response.addheader("content-disposition", "attachment; filename=" + pdffilepath + "");             response.writefile(pdffilepath);             response.end();         }         //return file(pdffilepath, "application/pdf", string.format("report{0}.pdf", 0));      } 

actually got p.d.f form here want customize own form database datas using itextsharper..

thanks in advance...

i solved issue use of html template.i designed template , binding template database datas..

public void add(int employeenumber, string fromdate, string todate)     {         string pdffilepath = null;         document doc = new document(itextsharp.text.pagesize.letter, 10, 10, 42, 35);         try         {             pdffilepath = server.mappath("~/yourpath/");              //string pdffilepath = server.mappath(".") + "/pdf/mypdf.pdf";             //create document class object , set size letter , give space left, right, top, bottom  margin             pdfwriter wri = pdfwriter.getinstance(doc, new filestream(pdffilepath, filemode.create));             //open document write             doc.open();              font font8 = fontfactory.getfont("arial", 7);             var titlefont = fontfactory.getfont("arial", 18, font.bold);             var subtitlefont = fontfactory.getfont("arial", 14, font.bold);             var boldtablefont = fontfactory.getfont("arial", 12, font.bold);             var endingmessagefont = fontfactory.getfont("arial", 10, font.italic);             var bodyfont = fontfactory.getfont("arial", 12, font.normal);              var imagefilepath = itextsharp.text.image.getinstance(server.mappath("~/images/8.jpg"));             itextsharp.text.image jpg = itextsharp.text.image.getinstance(imagefilepath);              //resize image depend upon need             jpg.scaletofit(40f, 56f);              //give space before image             jpg.spacingbefore = 30f;              //give space after image             jpg.spacingafter = 1f;             jpg.alignment = element.align_left;             doc.add(jpg);               //this month name , year name frm sql based on passed date             var dateresult = new salarydal().getmonthyear(fromdate);              //getting single property form collection in c#//             string contents = system.io.file.readalltext(server.mappath("~/templates/salarypdf.htm"));              var result = new salarydal().getsalaryreport(employeenumber, fromdate, todate);             contents = contents.replace("${companyname}", convert.tostring(result.gettype().getproperty("companyname").getvalue(result, null)));             contents = contents.replace("${month}", convert.tostring(dateresult.gettype().getproperty("month").getvalue(dateresult, null)));             contents = contents.replace("${year}", convert.tostring(dateresult.gettype().getproperty("year").getvalue(dateresult, null)));             contents = contents.replace("${employeename}", convert.tostring(result.gettype().getproperty("employeename").getvalue(result, null)));             contents = contents.replace("${accno}", convert.tostring(result.gettype().getproperty("bankaccno").getvalue(result, null)));             contents = contents.replace("${empno}", convert.tostring(result.gettype().getproperty("employeeno").getvalue(result, null)));             contents = contents.replace("${dptname}", convert.tostring(result.gettype().getproperty("department").getvalue(result, null)));             contents = contents.replace("${bankname}", convert.tostring(result.gettype().getproperty("bankname").getvalue(result, null)));             contents = contents.replace("${pfno}", convert.tostring(result.gettype().getproperty("pfno").getvalue(result, null)));             contents = contents.replace("${basic}", convert.tostring(result.gettype().getproperty("basicadd").getvalue(result, null)));             contents = contents.replace("${basic1}", convert.tostring(result.gettype().getproperty("basicsub").getvalue(result, null)));             contents = contents.replace("${hra}", convert.tostring(result.gettype().getproperty("hraadd").getvalue(result, null)));             contents = contents.replace("${hra1}", convert.tostring(result.gettype().getproperty("hrasub").getvalue(result, null)));             contents = contents.replace("${lta}", convert.tostring(result.gettype().getproperty("ltaadd").getvalue(result, null)));             contents = contents.replace("${lta1}", convert.tostring(result.gettype().getproperty("ltasub").getvalue(result, null)));             contents = contents.replace("${ta}", convert.tostring(result.gettype().getproperty("taadd").getvalue(result, null)));             contents = contents.replace("${ta1}", convert.tostring(result.gettype().getproperty("ltasub").getvalue(result, null)));             contents = contents.replace("${da}", convert.tostring(result.gettype().getproperty("daadd").getvalue(result, null)));             contents = contents.replace("${da1}", convert.tostring(result.gettype().getproperty("dasub").getvalue(result, null)));             contents = contents.replace("${bonus}", convert.tostring(result.gettype().getproperty("bonusadd").getvalue(result, null)));             contents = contents.replace("${bonus1}", convert.tostring(result.gettype().getproperty("bonussub").getvalue(result, null)));             contents = contents.replace("${pt}", convert.tostring(result.gettype().getproperty("ptadd").getvalue(result, null)));             contents = contents.replace("${pt1}", convert.tostring(result.gettype().getproperty("ptsub").getvalue(result, null)));             contents = contents.replace("${pf}", convert.tostring(result.gettype().getproperty("pfadd").getvalue(result, null)));             contents = contents.replace("${pf1}", convert.tostring(result.gettype().getproperty("pfsub").getvalue(result, null)));             contents = contents.replace("${other}", convert.tostring(result.gettype().getproperty("otheradd").getvalue(result, null)));             contents = contents.replace("${other1}", convert.tostring(result.gettype().getproperty("othersub").getvalue(result, null)));             contents = contents.replace("${ge}", convert.tostring(result.gettype().getproperty("grossearning").getvalue(result, null)));             contents = contents.replace("${gd}", convert.tostring(result.gettype().getproperty("grossdeduction").getvalue(result, null)));             contents = contents.replace("${netslry}", convert.tostring(result.gettype().getproperty("netsalary").getvalue(result, null)));               var parsedhtmlelements = htmlworker.parsetolist(new stringreader(contents), null);              foreach (var htmlelement in parsedhtmlelements)             {                 doc.add(htmlelement ielement);             }          }         catch (documentexception docex)         {          }         catch (ioexception ioex)         {          }         catch (exception ex)         {          }                 {             doc.close();             response.clearheaders();             response.contenttype = "application/pdf";             response.addheader("content-disposition", "attachment; filename=" + pdffilepath + "");             response.writefile(pdffilepath);             response.end();         }      } 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -