1 package reports; 2 3 import com.lowagie.text.*; 4 import com.lowagie.text.pdf.*; 5 import java.io.ByteArrayOutputStream ; 6 import dinamica.*; 7 8 16 public class PDFSalesReport extends AbstractPDFOutput 17 { 18 19 22 protected void createPDF( 23 GenericTransaction data, 24 ByteArrayOutputStream buf) 25 throws Throwable  26 { 27 28 Document doc = new Document(); 30 PdfWriter docWriter = PdfWriter.getInstance(doc, buf); 31 doc.setPageSize(PageSize.LETTER); 32 33 HeaderFooter header = new HeaderFooter(new Phrase(getHeader()), false); 35 header.setBorder(Rectangle.BOTTOM); 36 header.setAlignment(Rectangle.ALIGN_CENTER); 37 doc.setHeader(header); 38 39 HeaderFooter footer = new HeaderFooter(new Phrase(getFooter()), true); 41 footer.setBorder(Rectangle.TOP); 42 footer.setAlignment(Rectangle.ALIGN_RIGHT); 43 doc.setFooter(footer); 44 45 doc.open(); 46 47 Paragraph t = new Paragraph(getReportTitle(),new Font(Font.HELVETICA, 18f)); 49 t.setAlignment(Rectangle.ALIGN_CENTER); 50 doc.add(t); 51 52 PdfPTable totals = getTotalsSection(data); 54 totals.setSpacingBefore(20); 55 doc.add(totals); 56 57 doc.add(new Paragraph(" ")); 59 60 String ctx = getRequest().getContextPath(); 62 int port = getRequest().getServerPort(); 63 Image img = Image.getInstance(getImage("http://localhost:" + port + ctx + "/action/saleschart-pdf/chart", false)); 64 img.setAlignment(Element.ALIGN_CENTER); 65 doc.add(img); 66 67 doc.close(); 68 docWriter.close(); 69 70 } 71 72 77 PdfPTable getTotalsSection(GenericTransaction data) throws Throwable  78 { 79 80 83 84 Recordset rs = data.getRecordset("sales.sql"); 86 rs.top(); 87 88 PdfPTable datatable = new PdfPTable(2); 90 91 datatable.getDefaultCell().setPadding(3); 93 int headerwidths[] = {70, 30}; datatable.setWidths(headerwidths); 95 datatable.setWidthPercentage(50); datatable.setHorizontalAlignment(Element.ALIGN_CENTER); 97 datatable.getDefaultCell().setBorderWidth(1); 98 datatable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); 99 datatable.getDefaultCell().setGrayFill(0.9f); 100 datatable.addCell("Product Category"); 101 datatable.addCell("Total Sales US$"); 102 datatable.setHeaderRows(1); 103 datatable.getDefaultCell().setGrayFill(0.0f); 104 105 while (rs.next()) 107 { 108 datatable.addCell(rs.getString("categoryname")); 109 110 PdfPCell c = new PdfPCell(new Phrase(StringUtil.formatNumber(rs.getValue("subtotal"), "#,##0.00"))); 111 c.setHorizontalAlignment(Element.ALIGN_RIGHT); 112 datatable.addCell(c); 113 } 114 115 return datatable; 116 117 } 118 119 } 120
| Popular Tags
|