List of usage examples for com.lowagie.text Font TIMES_ROMAN
int TIMES_ROMAN
To view the source code for com.lowagie.text Font TIMES_ROMAN.
Click Source Link
From source file:org.posterita.core.TabularReport.java
License:Open Source License
public byte[] getInventoryData() throws DocumentException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, bos); document.open();// w w w. java 2s . c om // Font Syle Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD); Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD); Font style3 = new Font(Font.TIMES_ROMAN, 8.0f); Font style4 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD); float[] widths = { 1f, 1f, 0.55f, 0.55f, 0.55f, 1f, 1f, 1f, 1f }; // Table header PdfPTable mytable = new PdfPTable(9); mytable.setTotalWidth(widths); mytable.setWidthPercentage(100f); PdfPCell header = new PdfPCell(new Paragraph(getTitle() + "\n" + getSubtitle(), style1)); header.setColspan(9); header.setHorizontalAlignment(Element.ALIGN_CENTER); header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(header); // Table sub header PdfPCell subheader = new PdfPCell(); subheader = new PdfPCell(new Paragraph("")); subheader.setColspan(2); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("QUANTITY", style2)); subheader.setColspan(3); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("DIFFERENCE", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); // Rows Header PdfPCell rowHeader = new PdfPCell(new Paragraph("BARCODE", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("PRODUCT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("CSV", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("BOOK", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("COUNT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("BOOK", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("COUNT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("QUANTITY", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); document.add(mytable); Object[] headers = reportData.get(0); PdfPTable table = new PdfPTable(headers.length); table.setTotalWidth(widths); table.setWidthPercentage(100f); for (Object[] row : reportData) { for (Object data : row) { PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3)); table.addCell(dataCell); } } document.add(table); document.close(); return bos.toByteArray(); }
From source file:org.posterita.core.TabularReportMerge.java
License:Open Source License
public byte[] getPDFData() throws DocumentException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, bos); document.open();// w ww . j ava2 s . c o m // Font Syle Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD); Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD); Font style3 = new Font(Font.TIMES_ROMAN, 8.0f); Font style4 = new Font(Font.TIMES_ROMAN, 9.0f, Font.BOLD); float[] widths = { 2f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f }; // Table header PdfPTable mytable = new PdfPTable(7); mytable.setTotalWidth(widths); mytable.setWidthPercentage(100f); PdfPCell header = new PdfPCell( new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1)); header.setColspan(7); header.setHorizontalAlignment(Element.ALIGN_CENTER); header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(header); // Table sub header PdfPCell subheader = new PdfPCell(); subheader = new PdfPCell(new Paragraph("")); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("QUANTITY", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("VALUE (Excl. VAT)", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); subheader = new PdfPCell(new Paragraph("DISCREPANCY", style2)); subheader.setColspan(2); subheader.setHorizontalAlignment(Element.ALIGN_CENTER); mytable.addCell(subheader); // Rows Header PdfPCell rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("BOOK", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("COUNT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("BOOK", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("COUNT", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("QTY", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("VALUE", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); document.add(mytable); Object[] headers = reportData.get(0); PdfPTable table = new PdfPTable(headers.length); table.setTotalWidth(widths); table.setWidthPercentage(100f); for (Object[] row : reportData) { for (Object data : row) { PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3)); table.addCell(dataCell); } } document.add(table); document.close(); return bos.toByteArray(); }
From source file:org.posterita.core.TabularReportMerge.java
License:Open Source License
/** * Get Selling Items Data/*from w ww . j a v a2 s . c o m*/ * @return * @throws DocumentException * @throws OperationException */ public byte[] getSellingItemsData() throws DocumentException, OperationException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, bos); document.open(); // Font Syle Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD); Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD); Font style3 = new Font(Font.TIMES_ROMAN, 8.0f); Font style4 = new Font(Font.TIMES_ROMAN, 9.0f, Font.BOLD); Font style5 = new Font(Font.TIMES_ROMAN, 6.0f); float[] widths = { 2f, 0.5f, 0.5f, 1.0f }; // Table header PdfPTable mytable = new PdfPTable(4); mytable.setTotalWidth(widths); mytable.setWidthPercentage(100f); PdfPCell header = new PdfPCell( new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1)); header.setColspan(4); header.setHorizontalAlignment(Element.ALIGN_CENTER); header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(header); //Date Header PdfPCell dateHeader = new PdfPCell(new Paragraph("From : " + new Chunk( TimestampConvertor.convertTimeStamp(fromDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1), style1)); dateHeader.setColspan(1); dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT); dateHeader.setBackgroundColor(Color.GRAY); dateHeader.setBorderColor(Color.WHITE); mytable.addCell(dateHeader); dateHeader = new PdfPCell(new Paragraph("To : " + new Chunk( TimestampConvertor.convertTimeStamp(toDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1), style1)); dateHeader.setColspan(3); dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT); dateHeader.setBackgroundColor(Color.GRAY); dateHeader.setBorderColor(Color.WHITE); mytable.addCell(dateHeader); // Info Header PdfPCell infoHeader = new PdfPCell( new Paragraph("ALL VALUES ARE EXCLUSIVE OF VAT - SALES FIGURES ARE TAKEN AFTER DISCOUNT", style5)); infoHeader.setColspan(4); infoHeader.setHorizontalAlignment(Element.ALIGN_CENTER); infoHeader.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(infoHeader); // Rows Header PdfPCell rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("QTY", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("VALUE", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("SUPPLIER", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); document.add(mytable); Object[] headers = reportData.get(0); PdfPTable table = new PdfPTable(headers.length); table.setTotalWidth(widths); table.setWidthPercentage(100f); for (Object[] row : reportData) { for (Object data : row) { PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3)); table.addCell(dataCell); } } document.add(table); document.close(); return bos.toByteArray(); }
From source file:org.posterita.core.TabularReportMerge.java
License:Open Source License
/** * Get Stock Enquiry Report Data/*from w w w .j av a 2 s .c o m*/ * @return * @throws DocumentException * @throws OperationException */ public byte[] getStockEnquiryData() throws DocumentException, OperationException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); Document document = new Document(PageSize.A4); PdfWriter pdfWriter = PdfWriter.getInstance(document, bos); document.open(); // Font Syle Font style1 = new Font(Font.TIMES_ROMAN, 12.0f, Font.BOLD); Font style2 = new Font(Font.TIMES_ROMAN, 8.0f, Font.BOLD); Font style3 = new Font(Font.TIMES_ROMAN, 8.0f); Font style4 = new Font(Font.TIMES_ROMAN, 7.0f, Font.BOLD); Font style5 = new Font(Font.TIMES_ROMAN, 6.0f); float[] widths = { 1f, 2f, 0.5f, 0.5f, 0.5f, 0.5f }; // Table header PdfPTable mytable = new PdfPTable(6); mytable.setTotalWidth(widths); mytable.setWidthPercentage(100f); PdfPCell header = new PdfPCell( new Paragraph(new Chunk(title, style1) + "\n" + new Chunk(subtitle, style2) + "\n", style1)); header.setColspan(6); header.setHorizontalAlignment(Element.ALIGN_CENTER); header.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(header); //Date Header PdfPCell dateHeader = new PdfPCell(new Paragraph("From : " + new Chunk( TimestampConvertor.convertTimeStamp(fromDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1), style1)); dateHeader.setColspan(2); dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT); dateHeader.setBackgroundColor(Color.GRAY); dateHeader.setBorderColor(Color.WHITE); mytable.addCell(dateHeader); dateHeader = new PdfPCell(new Paragraph("To : " + new Chunk( TimestampConvertor.convertTimeStamp(toDate, TimestampConvertor.DEFAULT_DATE_PATTERN1), style1), style1)); dateHeader.setColspan(4); dateHeader.setHorizontalAlignment(Element.ALIGN_LEFT); dateHeader.setBackgroundColor(Color.GRAY); dateHeader.setBorderColor(Color.WHITE); mytable.addCell(dateHeader); // Info Header PdfPCell infoHeader = new PdfPCell( new Paragraph("ALL VALUES ARE EXCLUSIVE OF VAT & BASED ON PURCHASE PRICES", style5)); infoHeader.setColspan(6); infoHeader.setHorizontalAlignment(Element.ALIGN_CENTER); infoHeader.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); mytable.addCell(infoHeader); // Rows Header PdfPCell rowHeader = new PdfPCell(new Paragraph("BARCODE", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("PRODUCT NAME", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("Opening Stock Qty", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("Opening Stock Value", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("Closing Stock Qty", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); rowHeader = new PdfPCell(new Paragraph("Closing Stock Value", style4)); rowHeader.setHorizontalAlignment(Element.ALIGN_LEFT); mytable.addCell(rowHeader); document.add(mytable); Object[] headers = reportData.get(0); PdfPTable table = new PdfPTable(headers.length); table.setTotalWidth(widths); table.setWidthPercentage(100f); for (Object[] row : reportData) { for (Object data : row) { PdfPCell dataCell = new PdfPCell(new Phrase(data.toString(), style3)); table.addCell(dataCell); } } document.add(table); document.close(); return bos.toByteArray(); }
From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java
License:Educational Community License
public EvalPDFReportBuilder(OutputStream outputStream) { document = new Document(); try {//from www. jav a 2 s . com pdfWriter = PdfWriter.getInstance(document, outputStream); pdfWriter.setStrictImageSequence(true); document.open(); // attempting to handle i18n chars better // BaseFont evalBF = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.IDENTITY_H, // BaseFont.EMBEDDED); // paragraphFont = new Font(evalBF, 9, Font.NORMAL); // paragraphFont = new Font(Font.TIMES_ROMAN, 9, Font.NORMAL); titleTextFont = new Font(Font.TIMES_ROMAN, 22, Font.BOLD); boldTextFont = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); questionTextFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); paragraphFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.NORMAL); paragraphFontBold = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.BOLD); frontTitleFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, frontTitleSize, Font.NORMAL); frontAuthorFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 18, Font.NORMAL); frontInfoFont = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.NORMAL); } catch (Exception e) { throw UniversalRuntimeException.accumulate(e, "Unable to start PDF Report"); } }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph reportTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, 26, Font.NORMAL, new Color(23, 54, 93))); para.setSpacingAfter(15);// ww w . j av a2s . co m return para; }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph elementTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, 13, Font.BOLD, new Color(79, 129, 189))); para.setSpacingBefore(10);/* www.j ava2s.co m*/ return para; }
From source file:org.sonar.report.pdf.DefaultPDFReporter.java
License:Open Source License
private void printDashboard(Project project, Section section) throws DocumentException { PdfPTable dashboard = new PdfPTable(3); dashboard.getDefaultCell().setBorderColor(Color.WHITE); Font titleFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.BLACK); Font dataFont = new Font(Font.TIMES_ROMAN, 14, Font.BOLD, Color.GRAY); Font dataFont2 = new Font(Font.TIMES_ROMAN, 10, Font.BOLD, new Color(100, 150, 190)); PdfPTable linesOfCode = new PdfPTable(1); linesOfCode.getDefaultCell().setBorderColor(Color.WHITE); linesOfCode.addCell(new Phrase(getTextProperty("general.lines_of_code"), titleFont)); linesOfCode.addCell(new Phrase(project.getMeasure("ncss").getFormatValue(), dataFont)); linesOfCode.addCell(/* w w w .j a v a2s . c om*/ new Phrase(project.getMeasure("packages_count").getFormatValue() + " packages", dataFont2)); linesOfCode .addCell(new Phrase(project.getMeasure("classes_count").getFormatValue() + " classes", dataFont2)); linesOfCode.addCell( new Phrase(project.getMeasure("functions_count").getFormatValue() + " methods", dataFont2)); linesOfCode.addCell(new Phrase( project.getMeasure("duplicated_lines_ratio").getFormatValue() + " duplicated lines", dataFont2)); PdfPTable comments = new PdfPTable(1); comments.getDefaultCell().setBorderColor(Color.WHITE); comments.addCell(new Phrase(getTextProperty("general.comments"), titleFont)); comments.addCell(new Phrase(project.getMeasure("comment_ratio").getFormatValue(), dataFont)); comments.addCell( new Phrase(project.getMeasure("comment_lines").getFormatValue() + " comment lines", dataFont2)); PdfPTable codeCoverage = new PdfPTable(1); codeCoverage.getDefaultCell().setBorderColor(Color.WHITE); codeCoverage.addCell(new Phrase(getTextProperty("general.test_count"), titleFont)); codeCoverage.addCell(new Phrase(project.getMeasure("test_count").getFormatValue(), dataFont)); codeCoverage.addCell( new Phrase(project.getMeasure("test_success_percentage").getFormatValue() + " success", dataFont2)); codeCoverage .addCell(new Phrase(project.getMeasure("code_coverage").getFormatValue() + " coverage", dataFont2)); PdfPTable complexity = new PdfPTable(1); complexity.getDefaultCell().setBorderColor(Color.WHITE); complexity.addCell(new Phrase(getTextProperty("general.complexity"), titleFont)); complexity.addCell(new Phrase(project.getMeasure("ccn_function").getFormatValue(), dataFont)); complexity.addCell(new Phrase(project.getMeasure("ccn_class").getFormatValue() + " /class", dataFont2)); complexity.addCell(new Phrase(project.getMeasure("ccn").getFormatValue() + " decision points", dataFont2)); PdfPTable rulesCompliance = new PdfPTable(1); rulesCompliance.getDefaultCell().setBorderColor(Color.WHITE); rulesCompliance.addCell(new Phrase(getTextProperty("general.rules_compliance"), titleFont)); rulesCompliance.addCell(new Phrase(project.getMeasure("rules_compliance").getFormatValue(), dataFont)); PdfPTable violations = new PdfPTable(1); violations.getDefaultCell().setBorderColor(Color.WHITE); violations.addCell(new Phrase(getTextProperty("general.violations"), titleFont)); violations.addCell(new Phrase(project.getMeasure("rules_violations").getFormatValue(), dataFont)); dashboard.addCell(linesOfCode); dashboard.addCell(comments); dashboard.addCell(codeCoverage); dashboard.addCell(complexity); dashboard.addCell(rulesCompliance); dashboard.addCell(violations); dashboard.setSpacingBefore(8); section.add(dashboard); Image ccnDistGraph = getCCNDistribution(project); if (ccnDistGraph != null) { section.add(ccnDistGraph); Paragraph imageFoot = new Paragraph(getTextProperty("metrics.ccn_classes_count_distribution"), Style.FOOT_FONT); imageFoot.setAlignment(Paragraph.ALIGN_CENTER); section.add(imageFoot); } }
From source file:permit.InvoicePdf.java
License:Open Source License
/** * handles the letter header/*from w w w . ja v a2 s.co m*/ */ PdfPTable getHeader() { // String str = ""; String spacer = " "; PdfPTable headTable = null; try { // // for http url use // Image image = Image.getInstance(url + "js/images/city_logo3.jpg"); Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); float[] widths = { 25f, 40f, 35f }; // percentages headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); image.scalePercent(15f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headTable.addCell(cell); // float[] width = { 33f }; PdfPTable midTable = new PdfPTable(width); midTable.setWidthPercentage(33); midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); Phrase phrase = new Phrase(); Chunk ch = new Chunk("City of Bloomington ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Planning and Transportation Department ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // headTable.addCell(midTable); // PdfPTable rightTable = new PdfPTable(width); rightTable.setWidthPercentage(33); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); phrase = new Phrase(); ch = new Chunk("401 N Morton St Suite 130 ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); headTable.addCell(rightTable); } catch (Exception ex) { logger.error(ex); } return headTable; }
From source file:permit.InvoicePdf.java
License:Open Source License
void writePages(HttpServletResponse res, Invoice invoice) { ////from w ww . ja va 2 s. c om // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String fileName = "row_invoice_" + invoice.getInvoice_num() + ".pdf"; Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18); ServletOutputStream out = null; Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL); Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD); String spacer = " "; PdfPTable header = getHeader(); Company company = invoice.getCompany(); Contact contact = null; if (invoice.hasContact()) { contact = invoice.getContact(); } List<Page> pages = invoice.getPages(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); String str = ""; document.open(); document.add(header); // // title float[] width = { 100f }; // one cell PdfPTable table = new PdfPTable(width); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(new Phrase("INVOICE", fntb)); // cell.setBorder(Rectangle.BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); document.add(table); // // we need these later Paragraph pp = new Paragraph(); Chunk ch = new Chunk(" ", fntb); Phrase phrase = new Phrase(); // float[] widths = { 35f, 30f, 35f }; // percentages table = new PdfPTable(widths); table.setWidthPercentage(100.0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // // first row float[] widthOne = { 100f }; PdfPTable leftTable = new PdfPTable(widthOne); leftTable.setWidthPercentage(35.0f); leftTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // if (company != null) { ch = new Chunk("Company\n", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(company.getName() + "\n", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } if (contact != null) { phrase = new Phrase(); ch = new Chunk(contact.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(contact.getAddress(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); ch = new Chunk(contact.getCityStateZip(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } table.addCell(leftTable); // // middle cell // cell = new PdfPCell(new Phrase(spacer, fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // float[] widths2 = { 50f, 50f }; // percentages PdfPTable rightTable = new PdfPTable(widths2); rightTable.setWidthPercentage(35.0f); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // ch = new Chunk("Invoice No.", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getInvoice_num(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Status", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getStatus(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Invoice Date", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getDate(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("From ", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(invoice.getStart_date(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("To ", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(invoice.getEnd_date(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); table.addCell(rightTable); // // document.add(table); // phrase = new Phrase(new Chunk(spacer, fnt)); document.add(phrase); // int jj = 0; if (pages != null) { for (Page page : pages) { jj++; // float[] widthOne = {100f}; PdfPTable borderTable = new PdfPTable(widthOne); borderTable.setWidthPercentage(100.0f); borderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); float[] widthTwo = { 50f, 50f }; PdfPTable titleTable = new PdfPTable(widthTwo); titleTable.setWidthPercentage(75.0f); titleTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); phrase = new Phrase("Invoice No. ", fntb); ch = new Chunk(invoice.getInvoice_num(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // phrase = new Phrase(page.getPage_num(), fnt); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // borderTable.addCell(titleTable); float[] width4 = { 25f, 40f, 25f, 10f }; PdfPTable contTable = new PdfPTable(width4); cell = new PdfPCell(new Phrase("Excavation Permit Number", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Project", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Date Issued", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Permit Fee", fntb)); contTable.addCell(cell); List<Permit> permits = page.getPermits(); if (permits != null) { for (Permit permit : permits) { cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt)); contTable.addCell(cell); phrase = new Phrase(permit.getProject() + "\n", fnt); List<Excavation> cuts = permit.getExcavations(); if (cuts != null) { for (Excavation one : cuts) { ch = new Chunk(one.getAddress() + " (" + one.getCut_type() + ")", fnt); phrase.add(ch); } } cell = new PdfPCell(phrase); contTable.addCell(cell); cell = new PdfPCell(new Phrase(permit.getDate(), fnt)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); contTable.addCell(cell); cell = new PdfPCell(new Phrase(spacer, fnt)); // // space line cell.setColspan(4); contTable.addCell(cell); } } if (page.getNeededLines() > 0) { // first page for (int j = 0; j < page.getNeededLines(); j++) { cell = new PdfPCell(new Phrase(spacer, fnt)); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); } } if (jj == pages.size()) { cell = new PdfPCell(new Phrase("Total Invoice Amount\n" + invoice.getTotal(), fntb)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setColspan(4); contTable.addCell(cell); } borderTable.addCell(contTable); cell = new PdfPCell(new Phrase( "Payment due upon receipt. Please Make check payable to 'City of Bloomington'. Thank You.", fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); borderTable.addCell(cell); borderTable.addCell(titleTable); // invoice and date document.add(borderTable); if (jj < pages.size()) { document.newPage(); } } } // document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); // // if you want for users to download, uncomment the following line // // res.setHeader("Content-Disposition","attachment; filename="+fileName); res.setHeader("Pragma", "public"); // // setting the content type res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { logger.error(ex); } }