List of usage examples for com.lowagie.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:org.posterita.core.TabularReport.java
License:Open Source License
/** * Get Selling Items Data/* w ww . ja va 2 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(getTitle(), style1) + "\n" + new Chunk(getSubtitle(), 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.convertTimeStampToFyracleDate(fromDate), 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.convertTimeStampToFyracleDate(toDate), 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.TabularReport.java
License:Open Source License
/** * Get Stock Enquiry Report Data// w w w . j ava 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.convertTimeStampToFyracleDate(fromDate), 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.convertTimeStampToFyracleDate(toDate), 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.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();//from ww w . j a va 2 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, 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();/*from w w w . j a va2 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 w w. j a v a 2s . com * @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// w w w .j a v a 2 s . com * @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.primefaces.component.export.PDFExporter.java
License:Open Source License
protected void addTableFacets(FacesContext context, DataTable table, PdfPTable pdfTable, String facetType) { String facetText = null;//from www. ja va 2s . co m UIComponent facet = table.getFacet(facetType); if (facet != null) { if (facet instanceof UIPanel) { for (UIComponent child : facet.getChildren()) { if (child.isRendered()) { String value = ComponentUtils.getValueToRender(context, child); if (value != null) { facetText = value; break; } } } } else { facetText = ComponentUtils.getValueToRender(context, facet); } } if (facetText != null) { int colspan = 0; for (UIColumn col : table.getColumns()) { if (col.isRendered() && col.isExportable()) { colspan++; } } PdfPCell cell = new PdfPCell(new Paragraph(facetText, this.facetFont)); if (this.facetBgColor != null) { cell.setBackgroundColor(this.facetBgColor); } cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(colspan); pdfTable.addCell(cell); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the title page of the PDF document. * // w w w. j av a 2s . c om * @throws ExportException * If an error occurs while creating the title page */ private void writeTitlePage() throws ExportException { try { Font plainFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font boldFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font boldItalicFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading); /* * date and time of the meeting */ String meetingDate = sdfDate.format(meeting.getPlannedDate().getTime()); String meetingTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - " + sdfTime.format(meeting.getPlannedEnd().getTime()) + " [" + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]"; ; /* * Base table */ PdfPTable table = new PdfPTable(new float[] { 0.04f, 0.96f }); table.setWidthPercentage(100); table.setSplitRows(false); table.getDefaultCell().setBorderWidth(0); table.getDefaultCell().setPadding(0); /* * recipient of the invitation */ PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.addElement(phraseStrut); PdfPTable tableRecipient = new PdfPTable(2); tableRecipient.setWidthPercentage(100); tableRecipient.setSplitRows(false); tableRecipient.getDefaultCell().setBorderWidth(0); tableRecipient.getDefaultCell().setPadding(0); PdfPCell cellRecipient = new PdfPCell(); cellRecipient.setBorder(0); cellRecipient.setPadding(0); cellRecipient.addElement(new Phrase(translate("To:"), plainFontTitle)); cellRecipient.addElement(new Phrase(attendee.getName(), boldFontTitle)); tableRecipient.addCell(cellRecipient); PdfPCell cellDate = new PdfPCell(new Phrase(sdfDate.format(new Date().getTime()), plainFont)); cellDate.setHorizontalAlignment(Element.ALIGN_RIGHT); cellDate.setBorder(0); cellDate.setPadding(0); cellDate.setPaddingTop(7); tableRecipient.addCell(cellDate); cell.addElement(tableRecipient); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); /* * subject */ cell.addElement(new Phrase(translate("Invitation for the Meeting on") + " " + meetingDate, boldItalicFontTitle)); cell.addElement(phraseStrut); /* * invitation text */ Phrase phrase = new Phrase( Data.getInstance().getAppData().getSetting(AppSettingKey.PDF_INVITATION_TEXT), plainFont); phrase.setLeading(leading); cell.addElement(phrase); cell.addElement(phraseStrut); table.addCell(cell); /* * meeting date, time and location */ cell = new PdfPCell(new Phrase(meetingDate, boldItalicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(meetingTime, italicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); if (!meeting.getPlannedLocation().equals("")) { cell = new PdfPCell( new Phrase(translate("Location") + ": " + meeting.getPlannedLocation(), italicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } /* * role; review title and description */ cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.addElement(phraseStrut); cell.addElement(phraseStrut); phrase = new Phrase(); phrase.setLeading(leading); phrase.add(new Chunk(MessageFormat.format(translate("You are invited as {0} to this review ({1})."), translate(attendee.getRole().toString()), getReviewTitle()), boldFont)); cell.addElement(phrase); cell.addElement(phraseStrut); cell.addElement(new Phrase(resiData.getReview().getDescription(), italicFont)); cell.addElement(phraseStrut); /* * Predecessor meeting */ if (meetMgmt.getPredecessorMeeting(meeting) != null) { String preMeetingDate = sdfDate .format(meetMgmt.getPredecessorMeeting(meeting).getProtocol().getDate().getTime()); cell.addElement(new Phrase(MessageFormat .format(translate("This meeting ties up to the review meeting of {0}."), preMeetingDate), plainFont)); cell.addElement(phraseStrut); } /* * If there is a product name defined */ if (!Data.getInstance().getResiData().getReview().getProduct().getName().trim().equals("")) { /* * the product of this review */ cell.addElement(new Phrase(translate("The following product will be reviewed:"), plainFont)); cell.addElement(phraseStrut); table.addCell(cell); /* * Write name and version of the reviewed product */ Phrase phrName = new Phrase(Data.getInstance().getResiData().getReview().getProduct().getName(), boldItalicFont); phrName.setLeading(leading); PdfPCell cellName = new PdfPCell(phrName); cellName.setColspan(2); cellName.setBorderWidth(0); cellName.setPadding(padding); cellName.setPaddingBottom(0); cellName.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellName); /* * If there is a product version defined */ if (!Data.getInstance().getResiData().getReview().getProduct().getVersion().trim().equals("")) { Phrase phrVersion = new Phrase( translate("Product Version") + ": " + Data.getInstance().getResiData().getReview().getProduct().getVersion(), italicFont); phrVersion.setLeading(leading); PdfPCell cellVersion = new PdfPCell(phrVersion); cellVersion.setColspan(2); cellVersion.setBorderWidth(0); cellVersion.setPadding(padding); cellVersion.setPaddingBottom(0); cellVersion.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellVersion); } table.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 2)); } else { table.addCell(cell); } boolean showBottomStrut = false; /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); cellListPoint.setPaddingBottom(0); /* * Textual references */ for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) { Phrase phraseRef = new Phrase(ref, italicFontSmall); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); table.addCell(cellListPoint); table.addCell(cellRef); showBottomStrut = true; } /* * External file references */ for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), italicFontSmall)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFontSmall)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); table.addCell(cellListPoint); if (attachProdExtRefs) { cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); } table.addCell(cellRef); showBottomStrut = true; } if (showBottomStrut) { table.addCell(createVerticalStrut(PDFTools.cmToPt(0.4f), 2)); } /* * "please prepare" for the reviwers; on questions ask moderators */ cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); phrase = new Phrase(); phrase.setLeading(leading); if (attendee.getAspects() != null) { phrase.add(new Chunk(translate( "Please prepare for the review meeting by checking the product for the aspects which are associated to you.") + " ", plainFont)); } List<Attendee> moderators = new ArrayList<Attendee>(); for (Attendee a : Application.getInstance().getAttendeeMgmt().getAttendees()) { if (a.getRole() == Role.MODERATOR) { moderators.add(a); } } if (moderators.size() == 1 && attendee.getRole() != Role.MODERATOR) { phrase.add(new Chunk(translate( "Please do not hesitate to contact the review moderator if you have any questions:") + " ", plainFont)); } else if (moderators.size() > 1 && attendee.getRole() != Role.MODERATOR) { phrase.add(new Chunk(translate( "Please do not hesitate to contact one of the review moderators if you have any questions:") + " ", plainFont)); } cell.addElement(phrase); Phrase phraseStrutSmall = new Phrase(" "); phraseStrutSmall.setLeading(leading / 2); if (moderators.size() > 0 && attendee.getRole() != Role.MODERATOR) { for (Attendee mod : moderators) { cell.addElement(phraseStrutSmall); cell.addElement(new Phrase(mod.getName(), boldFont)); cell.addElement(new Phrase(mod.getContact(), italicFont)); } } table.addCell(cell); pdfDoc.add(table); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot generate front page of the PDF document.")); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the aspects.//w ww . ja v a 2 s. co m * * @throws ExportException * If an error occurs while writing the aspects */ private void writeAspects() throws ExportException { /* * If the role of the attendee is not reviewer show all aspects */ List<Aspect> aspects = null; if (attendee.getRole() == Role.REVIEWER) { aspects = attMgmt.getAspects(attendee); } else { aspects = aspMgmt.getAspects(); } if (aspects.size() == 0) { return; } try { Font descriptionFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font directiveFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font categoryFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font reviewerFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); /* * Build base table for all attendees */ PdfPTable tableAspects = new PdfPTable(1); tableAspects.setWidthPercentage(100); tableAspects.setSplitRows(false); tableAspects.getDefaultCell().setBorderWidth(0); tableAspects.getDefaultCell().setPadding(0); boolean grayBackground = true; for (Aspect asp : aspects) { /* * Build table for one aspect */ PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f }); tableAspect.setWidthPercentage(100); tableAspect.getDefaultCell().setBorderWidth(0); tableAspect.getDefaultCell().setPadding(0); PdfPCell cellAspect = new PdfPCell(); cellAspect.setPadding(0); cellAspect.setBorder(0); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading * 0.4f); /* * directive and description of the aspect */ PdfPCell cell = new PdfPCell(); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingBottom(padding * 1.5f); cell.addElement(new Phrase(asp.getDirective(), directiveFont)); cell.addElement(phraseStrut); cell.addElement(new Phrase(asp.getDescription(), descriptionFont)); /* * the reviewers of this aspect (moderator only) */ if (attendee.getRole() == Role.MODERATOR) { cell.addElement(phraseStrut); cell.addElement(phraseStrut); String separator = ""; Phrase phraseReviewers = new Phrase(); phraseReviewers.setLeading(leading); phraseReviewers.setFont(reviewerFont); for (Attendee att : attMgmt.getAttendees()) { if (attMgmt.hasAspect(asp, att)) { phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont)); separator = " "; } } cell.addElement(phraseReviewers); } tableAspect.addCell(cell); /* * category of the aspect */ cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont)); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingTop(padding * 1.1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableAspect.addCell(cell); cellAspect.addElement(tableAspect); cellAspect.setPadding(0); cellAspect.setPaddingLeft(padding); cellAspect.setPaddingRight(padding); if (grayBackground == true) { grayBackground = false; cellAspect.setBackgroundColor(cellBackground); } else { grayBackground = true; } /* * Add aspect to the list */ tableAspects.addCell(cellAspect); } PdfPCell cellBottomLine = new PdfPCell(); cellBottomLine.setPadding(0); cellBottomLine.setBorderWidth(0); cellBottomLine.setBorderWidthBottom(1); cellBottomLine.setBorderColor(cellBackground); tableAspects.addCell(cellBottomLine); /* * Add the attendee base table to the document */ pdfDoc.add(tableAspects); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put aspects into the PDF document.")); } }
From source file:org.revager.export.PDFPageEventHelper.java
License:Open Source License
@Override public void onEndPage(PdfWriter writer, Document document) { int columnNumber; try {/* w ww . j a v a 2 s .co m*/ Rectangle page = document.getPageSize(); float pageWidth = page.getWidth() - document.leftMargin() - document.rightMargin(); /* * Write marks */ setMarks(writer, document); /* * Define fonts */ headBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); Font headFont = new Font(headBaseFont, headFontSize); footBaseFont = BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED); Font footFont = new Font(footBaseFont, footFontSize); /* * Cell fill for space between head/foot and content */ PdfPCell cellFill = new PdfPCell(); cellFill.setMinimumHeight(PDFTools.cmToPt(0.8f)); cellFill.setBorderWidth(0); /* * Write head */ if (headLogoPath != null) { columnNumber = 2; } else { columnNumber = 1; } PdfPTable head = new PdfPTable(columnNumber); Phrase phraseTitle = new Phrase(headTitle, headFont); PdfPCell cellTitle = new PdfPCell(phraseTitle); cellTitle.setHorizontalAlignment(Element.ALIGN_LEFT); cellTitle.setVerticalAlignment(Element.ALIGN_BOTTOM); cellTitle.setPaddingTop(0); cellTitle.setPaddingBottom(PDFTools.cmToPt(0.2f)); cellTitle.setPaddingLeft(0); cellTitle.setPaddingRight(0); cellTitle.setBorderWidthTop(0); cellTitle.setBorderWidthBottom(0.5f); cellTitle.setBorderWidthLeft(0); cellTitle.setBorderWidthRight(0); head.addCell(cellTitle); if (headLogoPath != null) { Image headLogo = Image.getInstance(headLogoPath); headLogo.scaleToFit(PDFTools.cmToPt(5.0f), PDFTools.cmToPt(1.1f)); PdfPCell cellLogo = new PdfPCell(headLogo); cellLogo.setHorizontalAlignment(Element.ALIGN_RIGHT); cellLogo.setVerticalAlignment(Element.ALIGN_BOTTOM); cellLogo.setPaddingTop(0); cellLogo.setPaddingBottom(PDFTools.cmToPt(0.15f)); cellLogo.setPaddingLeft(0); cellLogo.setPaddingRight(0); cellLogo.setBorderWidthTop(0); cellLogo.setBorderWidthBottom(0.5f); cellLogo.setBorderWidthLeft(0); cellLogo.setBorderWidthRight(0); head.addCell(cellLogo); head.addCell(cellFill); } head.addCell(cellFill); head.setTotalWidth(pageWidth); head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(), writer.getDirectContent()); /* * Write foot */ if (footText == null) { footText = " "; } PdfPTable foot = new PdfPTable(1); foot.addCell(cellFill); PdfPCell cellFootText = new PdfPCell(new Phrase(footText, footFont)); cellFootText.setHorizontalAlignment(Element.ALIGN_RIGHT); cellFootText.setVerticalAlignment(Element.ALIGN_TOP); cellFootText.setPaddingTop(PDFTools.cmToPt(0.15f)); cellFootText.setPaddingBottom(0); cellFootText.setPaddingLeft(0); cellFootText.setPaddingRight(0); cellFootText.setBorderWidthTop(0.5f); cellFootText.setBorderWidthBottom(0); cellFootText.setBorderWidthLeft(0); cellFootText.setBorderWidthRight(0); foot.addCell(cellFootText); /* * Print page numbers */ PdfContentByte contentByte = writer.getDirectContent(); contentByte.saveState(); String text = MessageFormat.format(translate("Page {0} of") + " ", writer.getPageNumber()); float textSize = footBaseFont.getWidthPoint(text, footFontSize); float textBase = document.bottom() - PDFTools.cmToPt(1.26f); contentByte.beginText(); contentByte.setFontAndSize(footBaseFont, footFontSize); float adjust; if (footText.trim().equals("")) { adjust = (pageWidth / 2) - (textSize / 2) - footBaseFont.getWidthPoint("0", footFontSize); } else { adjust = 0; } contentByte.setTextMatrix(document.left() + adjust, textBase); contentByte.showText(text); contentByte.endText(); contentByte.addTemplate(template, document.left() + adjust + textSize, textBase); contentByte.stroke(); contentByte.restoreState(); foot.setTotalWidth(pageWidth); foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(), writer.getDirectContent()); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExceptionConverter(e); } }