Creating dynamic html in java with itext best way to approach -
im using example found on stackoverflow explain problem.
java code :
/** * example written bruno lowagie in answer following question: * rowspan not work in itextsharp? */
public class parsehtml { public static final string dest = "results/xmlworker/html_table_4.pdf"; public static final string html = "d:\\users\\documenten\\netbeansprojects\\itexttest\\recources\\xml\\table2_css.html"; public static void main(string[] args) throws ioexception, documentexception { file file = new file(dest); file.getparentfile().mkdirs(); new parsehtml().createpdf(dest); } /** * creates pdf words "hello world" * @param file * @throws ioexception * @throws documentexception */ public void createpdf(string file) throws ioexception, documentexception { // step 1 document document = new document(); // step 2 pdfwriter writer = pdfwriter.getinstance(document, new fileoutputstream(file)); // step 3 document.open(); // step 4 // xmlworkerhelper.getinstance().parsexhtml(writer, document, null, null); xmlworkerhelper.getinstance().parsexhtml(writer, document, new fileinputstream(html)); // step 5 document.close(); }
}
html code:
<table border="1" style="width: 100%"> <tr> <td colspan="5" align="center" style="background-color: lightblue">invoice</td> </tr> <tr> <td colspan="2" rowspan="4" style="background-color: white"><b>airnet networks</b><br />asdadadadaada asd asd ads adsadsadsadasd</td> <td>invoice</td> <td>date</td> <td>adatesd</td> </tr> <tr> <td>order</td> <td>xxxx</td> <td>ref xxxxxx</td> </tr> <tr> <td>delivery</td> <td>xxxx</td> <td>ref xxxxxx</td> </tr> <tr> <td>due date</td> <td>xxxx</td> <td>ref xxxxxx</td> </tr> <tr> <td colspan="2" rowspan="4" style="background-color: white"><p><b >customer name</b></p> asd asd adadaadadadada adadaadsasdad ada asd adad</td> <td>customer care no:</td> <td colspan="2">544646454,88877978975</td> </tr> <tr> <td>email id</td> <td colspan="2">airnet@gmail.com</td> </tr> <tr> <td>account details</td> <td colspan="2">5522245125545455 ifsc 323hasd<br /> sbi india</td> </tr> </table> <div> </div> <table border="1" style="width: 100%"> <tr> <td style="background-color: lightblue" height="15" >srno</td> <td style="background-color: lightblue">particulars</td> <td style="background-color: lightblue">quantity</td> <td style="background-color: lightblue">rate/month</td> <td style="background-color: lightblue">total rupees</td> </tr> <tr> <td valign="top">1</td> <td valign="top">1 mbps plan</td> <td valign="top">1</td> <td valign="top">600</td> <td valign="top">692</td> </tr> <tr> <td height="300" valign="top" >1</td> <td valign="top">1 mbps plan</td> <td valign="top">1</td> <td valign="top">600</td> <td valign="top">692</td> </tr> <tr> <td colspan="3" rowspan="3" valign="top">asdasdasd</td> <td colspan="1">total</td> <td colspan="1">692</td> </tr> <tr> <td>service tax</td> <td>692</td> </tr> <tr> <td>grand total</td> <td>692</td> </tr> </table>
the problems im facing: possible give html access javaclass can use this:
<tr> <td>invoice.getdate</td> <td>invoice.getinvoicenumber</td> <td>invoice.getsomethingelse</td> </tr>
can create dynamic table this:
<table border="1" style="width: 100%"> <tr> <td style="background-color: lightblue" height="15" >srno</td> <td style="background-color: lightblue">particulars</td> <td style="background-color: lightblue">quantity</td> <td style="background-color: lightblue">rate/month</td> <td style="background-color: lightblue">total rupees</td> </tr> (servicedto service : listservices) { <tr> <td valign="top">service.getsomevalue</td> <td valign="top">service.getsomevalue</td> <td valign="top">service.getsomevalue</td> <td valign="top">service.getsomevalue</td> <td valign="top">service.getsomevalue</td> </tr> }
as work around im using stringbuilder. create temporarily html page load html page inside itext. there has better way ? can give me direction start ?
Comments
Post a Comment