In recent days, the project needs to generate a PDF report, the online search of Java generated PDF file, there are probably two kinds, one is to use Jacob call Excel Save as PDF file, another is
With the Third-party Open Source Library Itext.jar directly generated PDF files, both of which I have tried, combined with the needs of the project, feel or use Itext to generate PDF reports more free. Here is the sample code that records
Itext how to simply generate PDF files and tables.
String path = Uatsresources.getapppath () +uats.getitem () + "/test-report.pdf";
Com.lowagie.text.Document Document = new Com.lowagie.text.Document ();
Pdfwriter.getinstance (document, new FileOutputStream (path));
Document.open ();
Basefont style = Basefont.createfont ("Stsongstd-light", "Unigb-ucs2-h", false);
Font chinese = new Font (style, 8, font.bold,color.black);
pdfptable table = new Pdfptable (10);
Table.addcell (New Pdfpcell ("number", Chinese));
Table.addcell (New Pdfpcell ("Application Name", Chinese));
Table.addcell (New Pdfpcell ("File type", Chinese));
Table.addcell (New Pdfpcell ("Application Version", Chinese));
Table.addcell (New Pdfpcell ("Installation", Chinese));
Table.addcell (New Pdfpcell ("Application Startup", Chinese));
Table.addcell (New Pdfpcell ("Application Exit", Chinese));
Table.addcell (New Pdfpcell ("Application Run", Chinese)); Table.addcell (New Pdfpcell Phrase ("Uninstall condition", CHInese)));
Table.addcell (New Pdfpcell ("Test Type", Chinese));
Table.addcell (New Pdfpcell ("Security check", Chinese));
Table.addcell (New Pdfpcell ("Start Time", Chinese));
Table.addcell (New Pdfpcell ("CPU footprint", Chinese));
Table.addcell (New Pdfpcell ("Memory footprint", Chinese));
Table.addcell (New Pdfpcell ("Test Time", Chinese));
Table.addcell (New Pdfpcell Phrase ("Tester", Chinese));
Document.add (table);
Document.close ();