List of usage examples for com.lowagie.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.lowagie.text Element ALIGN_LEFT.
Click Source Link
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfLogicalPageDrawable.java
License:Open Source License
private int mapAlignment(final RenderableComplexText node) { ElementAlignment alignment;/* w w w. j a v a 2 s . co m*/ if (node.getNext() == null) { alignment = paragraphContext.getLastLineAlignment(); } else { alignment = paragraphContext.getTextAlignment(); } if (ElementAlignment.LEFT.equals(alignment)) { return Element.ALIGN_LEFT; } else if (ElementAlignment.RIGHT.equals(alignment)) { return Element.ALIGN_RIGHT; } else if (ElementAlignment.CENTER.equals(alignment)) { return Element.ALIGN_CENTER; } else { return Element.ALIGN_JUSTIFIED; } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.helper.RTFPrinter.java
License:Open Source License
private void computeCellStyle(final RenderBox content, final Cell cell) { final ElementAlignment verticalAlign = content.getNodeLayoutProperties().getVerticalAlignment(); if (ElementAlignment.BOTTOM.equals(verticalAlign)) { cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } else if (ElementAlignment.MIDDLE.equals(verticalAlign)) { cell.setVerticalAlignment(Element.ALIGN_MIDDLE); } else {/*from w w w. j ava 2 s . c o m*/ cell.setVerticalAlignment(Element.ALIGN_TOP); } final ElementAlignment textAlign = (ElementAlignment) content.getStyleSheet() .getStyleProperty(ElementStyleKeys.ALIGNMENT); if (ElementAlignment.RIGHT.equals(textAlign)) { cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else if (ElementAlignment.JUSTIFY.equals(textAlign)) { cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); } else if (ElementAlignment.CENTER.equals(textAlign)) { cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.setHorizontalAlignment(Element.ALIGN_LEFT); } }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfRow.java
License:Open Source License
/** * Writes the row definition/settings.// w w w .jav a 2 s .co m * * @param result * The <code>OutputStream</code> to write the definitions to. */ private void writeRowDefinition(final OutputStream result) throws IOException { result.write(ROW_BEGIN); this.document.outputDebugLinebreak(result); result.write(ROW_WIDTH_STYLE); result.write(ROW_WIDTH); result.write(intToByteArray(this.width)); if (this.parentTable.getCellsFitToPage()) { result.write(ROW_KEEP_TOGETHER); } float minHeightInTwips = 0; for (int i = 0; i < this.cells.size(); i++) { PatchRtfCell rtfCell = this.cells.get(i); minHeightInTwips = Math.max(minHeightInTwips, rtfCell.getMinimumHeight()); } result.write(ROW_HEIGHT); result.write(intToByteArray((int) (minHeightInTwips * 20))); if (this.rowNumber <= this.parentTable.getHeaderRows()) { result.write(ROW_HEADER_ROW); } switch (this.parentTable.getAlignment()) { case Element.ALIGN_LEFT: result.write(ROW_ALIGN_LEFT); break; case Element.ALIGN_RIGHT: result.write(ROW_ALIGN_RIGHT); break; case Element.ALIGN_CENTER: result.write(ROW_ALIGN_CENTER); break; case Element.ALIGN_JUSTIFIED: case Element.ALIGN_JUSTIFIED_ALL: result.write(ROW_ALIGN_JUSTIFIED); break; } result.write(ROW_GRAPH); PatchRtfBorderGroup borders = this.parentTable.getBorders(); if (borders != null) { borders.writeContent(result); } if (this.parentTable.getCellSpacing() > 0) { result.write(ROW_CELL_SPACING_LEFT); result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2))); result.write(ROW_CELL_SPACING_LEFT_STYLE); result.write(ROW_CELL_SPACING_TOP); result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2))); result.write(ROW_CELL_SPACING_TOP_STYLE); result.write(ROW_CELL_SPACING_RIGHT); result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2))); result.write(ROW_CELL_SPACING_RIGHT_STYLE); result.write(ROW_CELL_SPACING_BOTTOM); result.write(intToByteArray((int) (this.parentTable.getCellSpacing() / 2))); result.write(ROW_CELL_SPACING_BOTTOM_STYLE); } result.write(ROW_CELL_PADDING_LEFT); result.write(intToByteArray((int) (this.parentTable.getCellPadding() / 2))); result.write(ROW_CELL_PADDING_RIGHT); result.write(intToByteArray((int) (this.parentTable.getCellPadding() / 2))); result.write(ROW_CELL_PADDING_LEFT_STYLE); result.write(ROW_CELL_PADDING_RIGHT_STYLE); this.document.outputDebugLinebreak(result); for (int i = 0; i < this.cells.size(); i++) { PatchRtfCell rtfCell = this.cells.get(i); rtfCell.writeDefinition(result); } }
From source file:org.posterita.core.CrossTabReportGenerator.java
License:Open Source License
protected void writeDocument(Document document) throws OperationException { try {// ww w .j a va2s .c o m int noOfRows = dataSource.size(); String longestText = ""; int columnCount = 0; Object[] obj = null; Object[] header = (Object[]) dataSource.get(0); columnCount = header.length; PdfPTable table = new PdfPTable(columnCount); table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setPaddingBottom(5); table.getDefaultCell().setPaddingTop(5); //adding the headers for (int i = 0; i < columnCount; i++) { if (i == 0) { longestText = header[i].toString(); table.addCell(new Paragraph(header[i].toString())); } else { Image img = getTextAsImage(header[i].toString()); img.setRotationDegrees(90); img.setAlignment(Image.ALIGN_BOTTOM); PdfPCell cell = new PdfPCell(img); cell.setPadding(4); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); //cell.setBackgroundColor(new Color(0, 0, 255)); table.addCell(cell); } } //adding the data for (int j = 1; j < noOfRows; j++) { obj = (Object[]) dataSource.get(j); for (int k = 0; k < columnCount; k++) { if (k == 0) { String text = obj[0].toString(); if (new Chunk(text, HEADER_FONT).getWidthPoint() > new Chunk(longestText, HEADER_FONT) .getWidthPoint()) { longestText = text; } Chunk txtck = new Chunk(obj[0].toString(), HEADER_FONT); PdfPCell cell = new PdfPCell(new Paragraph(txtck)); if (j == noOfRows - 1) { cell.setBackgroundColor(new Color(170, 170, 170)); } cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); cell.setPaddingLeft(5); table.addCell(cell); } else { Chunk txtck = new Chunk(obj[k].toString(), DATA_FONT); if (k == columnCount - 1) { PdfPCell cell = new PdfPCell(new Paragraph(txtck)); cell.setBackgroundColor(new Color(170, 170, 170)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); table.addCell(cell); } else { PdfPCell cell = new PdfPCell(new Paragraph(txtck)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingBottom(5); cell.setPaddingTop(5); if (j == noOfRows - 1) { cell.setBackgroundColor(new Color(170, 170, 170)); } table.addCell(cell); } } } } //setting table width Chunk dataChk = new Chunk("9999", DATA_FONT); Chunk headerChk = new Chunk(longestText, HEADER_FONT); float dataChkLength = dataChk.getWidthPoint() + 2 * CELLPADDING; float headerChkLength = headerChk.getWidthPoint() + 2 * CELLPADDING; float tableWidth = headerChkLength + dataChkLength * columnCount; float actualTableWidth = document.getPageSize().getWidth() - 2 * MARGIN; float columnWidth = dataChkLength; if (tableWidth < actualTableWidth) { columnWidth = (actualTableWidth - headerChkLength) / (columnCount - 1); } float[] widths = new float[columnCount]; widths[0] = headerChkLength + 2 * CELLPADDING; for (int i = 1; i < columnCount; i++) { widths[i] = columnWidth; } table.setWidths(widths); //writing the table document.add(table); } catch (DocumentException e) { throw new OperationException(e); } }
From source file:org.posterita.core.TabularReport.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 v a 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, 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(getTitle() + "\n" + getSubtitle(), 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.TabularReport.java
License:Open Source License
/** * Get Selling Items Data// ww w .j av a 2s.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/*from w w w . j a va 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.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 w ww . ja v a 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 ww .j a va 2s. 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// w w w . j a va 2 s . co 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(); }