List of usage examples for com.itextpdf.text.pdf PdfPTable setHorizontalAlignment
public void setHorizontalAlignment(final int horizontalAlignment)
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterDatumLine(String datumString, Font footerFont) throws DocumentException { PdfPCell labelCell = new PdfPCell(new Phrase("Datum", footerFont)); labelCell.setBorder(Rectangle.BOTTOM); labelCell.setBorderWidth(1f);//from w w w . j a v a2 s . c o m PdfPCell nameCell = new PdfPCell(new Phrase(datumString, footerFont)); nameCell.setBorder(Rectangle.BOTTOM); nameCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f); table.addCell(labelCell); table.addCell(nameCell); table.setWidths(new float[] { 0.3f, 0.7f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterDienstsiegelLine(Font footerFont) throws DocumentException { PdfPCell leftCell = new PdfPCell(new Phrase("", footerFont)); leftCell.setBorder(Rectangle.NO_BORDER); leftCell.setBorderWidth(1f);//from w ww.ja v a2 s . c om PdfPCell centerCell = new PdfPCell(new Phrase("Dienstsiegel der Schule", footerFont)); centerCell.setBorder(Rectangle.NO_BORDER); centerCell.setBorderWidth(1f); centerCell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell rightCell = new PdfPCell(new Phrase("", footerFont)); rightCell.setBorder(Rectangle.NO_BORDER); rightCell.setBorderWidth(1f); PdfPTable table = new PdfPTable(3); table.setHorizontalAlignment(Element.ALIGN_MIDDLE); table.setWidthPercentage(100f); table.addCell(leftCell); table.addCell(centerCell); table.addCell(rightCell); table.setWidths(new float[] { 0.3f, 0.3f, 0.3f }); return table; }
From source file:org.fossa.rolp.util.PdfFormatHelper.java
License:Open Source License
public static PdfPTable buildFooterKenntnisLine(Font footerFont) { PdfPCell cell = new PdfPCell(new Phrase("Kenntnis genommen: Erziehungsberechtigte", footerFont)); cell.setBorder(Rectangle.TOP); cell.setBorderWidth(1f);//from w ww .j a v a2s . c om cell.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setWidthPercentage(100f); table.addCell(cell); return table; }
From source file:org.inspira.condominio.pdf.DocumentoIngreso.java
private void addHousePicture(String imgResStr) throws BadElementException, IOException, DocumentException { Image image = Image.getInstance(imgResStr); PdfPTable table = new PdfPTable(1); table.setTotalWidth(image.getScaledWidth()); table.setLockedWidth(true);// w w w .j ava2 s . co m PdfPCell cell = new PdfPCell(); cell.setBorder(0); //cell.setCellEvent(new ImageBackgroundEvent(image)); cell.setFixedHeight(image.getScaledHeight()); table.addCell(cell); table.setHorizontalAlignment(PdfPTable.ALIGN_RIGHT); documento.add(table); }
From source file:org.larz.dom4.editor.ReportGenerator.java
License:Open Source License
private static PdfPTable getTable(String[] columns, String[] columnNames, ValueTranslator[] trans, ValueCombiner[] combine, List<Map.Entry<String, ModObject>> list) { PdfPTable table = new PdfPTable(columns.length); table.setWidthPercentage(100f);/*from ww w. java 2s. c o m*/ table.setHorizontalAlignment(Element.ALIGN_LEFT); for (String col : columnNames) { PdfPCell c = new PdfPCell(new Phrase(col, SUBTITLE)); c.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(c); } table.setHeaderRows(1); for (Map.Entry<String, ModObject> innerEntry : list) { String name = innerEntry.getValue().title; Map<String, PropertyValues> map = innerEntry.getValue().propertyMap; List<Map.Entry<String, PropertyValues>> list2 = new ArrayList<Map.Entry<String, PropertyValues>>(); for (Map.Entry<String, PropertyValues> innerEntry2 : map.entrySet()) { list2.add(innerEntry2); } Collections.sort(list2, new Comparator<Map.Entry<String, PropertyValues>>() { @Override public int compare(Map.Entry<String, PropertyValues> o1, Map.Entry<String, PropertyValues> o2) { return o1.getKey().compareTo(o2.getKey()); } }); if (list2.size() == 0) continue; PdfPCell[] cells = new PdfPCell[columns.length]; cells[0] = new PdfPCell(); cells[0].addElement(new Phrase(name, BOLD_TEXT)); for (int i = 1; i < cells.length; i++) { cells[i] = new PdfPCell(); if (combine != null && combine[i] != null) { String[] neededCols = combine[i].getNeededColumns(); String[] oldValues = new String[neededCols.length]; String[] newValues = new String[neededCols.length]; for (int j = 0; j < neededCols.length; j++) { for (Map.Entry<String, PropertyValues> entry : list2) { if (entry.getKey().equals(neededCols[j])) { oldValues[j] = entry.getValue().oldValue; newValues[j] = entry.getValue().newValue; break; } } } // Put old values into null new values boolean hasNew = false; for (int k = 0; k < newValues.length; k++) { if (newValues[k] != null) { hasNew = true; break; } } if (hasNew) { for (int k = 0; k < newValues.length; k++) { if (newValues[k] == null) { newValues[k] = oldValues[k]; } } } String newValue = combine[i].translate(newValues); String oldValue = combine[i].translate(oldValues); if (newValue != null) { Phrase phrase = new Phrase(); phrase.add(new Chunk(newValue, BOLD_TEXT)); if (oldValue != null) { phrase.add(new Chunk(" (" + oldValue + ")", TEXT)); } cells[i].addElement(phrase); } else if (oldValue != null) { cells[i].addElement(new Phrase(oldValue, TEXT)); } } else { for (Map.Entry<String, PropertyValues> entry : list2) { if (entry.getKey().equals(columns[i])) { String oldValue = entry.getValue().oldValue; String newValue = entry.getValue().newValue; if (trans != null && trans.length > i && trans[i] != null) { oldValue = trans[i].translate(oldValue); newValue = trans[i].translate(newValue); } if (newValue != null) { Phrase phrase = new Phrase(); phrase.add(new Chunk(newValue, BOLD_TEXT)); if (oldValue != null && !oldValue.equals("null")) { phrase.add(new Chunk(" (" + oldValue + ")", TEXT)); } cells[i].addElement(phrase); } else if (oldValue != null && !oldValue.equals("null")) { cells[i].addElement(new Phrase(oldValue, TEXT)); } break; } } } } for (PdfPCell cell : cells) { table.addCell(cell); } } return table; }
From source file:org.openlmis.web.view.pdf.requisition.RequisitionPdfModel.java
License:Open Source License
public PdfPTable getSummary() throws DocumentException { this.requisition.fillFullSupplyCost(); this.requisition.fillNonFullSupplyCost(); DecimalFormat formatter = new DecimalFormat("#,##0.00"); PdfPTable summaryTable = new PdfPTable(2); summaryTable.setWidths(new int[] { 30, 20 }); summaryTable.setSpacingBefore(TABLE_SPACING); summaryTable.setWidthPercentage(40); summaryTable.setHorizontalAlignment(0); PdfPCell summaryHeaderCell = headingCell(messageService.message("label.summary")); summaryHeaderCell.setColspan(2);/* w ww . j a v a 2 s . c o m*/ summaryHeaderCell.setPadding(10); summaryHeaderCell.setBorder(0); summaryTable.addCell(summaryHeaderCell); boolean showBudget = !requisition.isEmergency() && requisition.getProgram().getBudgetingApplies(); if (showBudget) { summaryTable.addCell(summaryCell(textCell(messageService.message("label.allocated.budget")))); PdfPCell allocatedBudgetCell = requisition.getAllocatedBudget() != null ? numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(new Money(requisition.getAllocatedBudget()).toDecimal())) : numberCell(messageService.message("msg.budget.not.allocated")); summaryTable.addCell(summaryCell(allocatedBudgetCell)); } summaryTable.addCell(summaryCell(textCell(messageService.message("label.total.cost.full.supply.items")))); summaryTable.addCell(summaryCell(numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(requisition.getFullSupplyItemsSubmittedCost().toDecimal())))); summaryTable .addCell(summaryCell(textCell(messageService.message("label.total.cost.non.full.supply.items")))); summaryTable.addCell(summaryCell(numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(requisition.getNonFullSupplyItemsSubmittedCost().toDecimal())))); summaryTable.addCell(summaryCell(textCell(messageService.message("label.total.cost")))); summaryTable.addCell(summaryCell(numberCell(messageService.message(LABEL_CURRENCY_SYMBOL) + formatter.format(this.getTotalCost(requisition).toDecimal()).toString()))); if (showBudget && requisition.getAllocatedBudget() != null && (requisition.getAllocatedBudget().compareTo(this.getTotalCost(requisition).getValue()) == -1)) { summaryTable.addCell(summaryCell(textCell(messageService.message("msg.cost.exceeds.budget")))); summaryTable.addCell(summaryCell(textCell(" "))); } summaryTable.addCell(summaryCell(textCell(" "))); summaryTable.addCell(summaryCell(textCell(" "))); summaryTable.addCell(summaryCell(textCell(" "))); summaryTable.addCell(summaryCell(textCell(" "))); fillAuditFields(summaryTable); return summaryTable; }
From source file:org.opensrp.web.utils.PdfUtil.java
License:Open Source License
public static ByteArrayOutputStream generatePdf(List<String> data, int width, int height, int copiesImage, int columnLimit) { try {/*from w w w . java 2s .c o m*/ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); Document document = new Document(); document.setMargins(MARGINS[0], MARGINS[1], MARGINS[2], MARGINS[3]); PdfWriter.getInstance(document, byteArrayOutputStream); document.open(); PdfPTable table = new PdfPTable(columnLimit); table.setTotalWidth(TABLE_WIDTH); table.setHorizontalAlignment(Element.ALIGN_LEFT); int length = 0; int count = 0; for (String str : data) { if (str.length() > 0 && str.length() <= 5) { length = 54; } else if (str.length() >= 6 && str.length() <= 9) { length = 44; } else if (str.length() >= 10 && str.length() <= 11) { length = 36; } else if (str.length() >= 12 && str.length() <= 14) { length = 27; } else if (str.length() >= 15 && str.length() <= 17) { length = 22; } else { length = 15; } Hashtable<EncodeHintType, ErrorCorrectionLevel> hintMap = new Hashtable<EncodeHintType, ErrorCorrectionLevel>(); hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L); QRCodeWriter qrCodeWriter = new QRCodeWriter(); BitMatrix byteMatrix = null; byteMatrix = qrCodeWriter.encode(str, BarcodeFormat.QR_CODE, width, height, hintMap); int matrixWidth = byteMatrix.getWidth(); int matrixHeight = byteMatrix.getHeight(); BufferedImage image = new BufferedImage(matrixWidth, matrixHeight, BufferedImage.TYPE_INT_RGB); image.createGraphics(); Graphics2D graphics = (Graphics2D) image.getGraphics(); graphics.setColor(Color.WHITE); graphics.fillRect(0, 0, matrixWidth + 5, matrixHeight + 5); graphics.setFont(graphics.getFont().deriveFont(13f)); graphics.setColor(Color.BLACK); graphics.drawString(str, length, height - 10); for (int i = 0; i < matrixHeight; i++) { for (int j = 0; j < matrixHeight; j++) { if (byteMatrix.get(i, j)) { graphics.fillRect((i), j, 1, 1); } } } Image itextImage = null; itextImage = Image.getInstance(Toolkit.getDefaultToolkit().createImage(image.getSource()), null); for (int i = 0; i < copiesImage; i++) { PdfPCell cell = new PdfPCell(itextImage); cell.setBorder(Rectangle.NO_BORDER); count++; table.addCell(cell); } } for (int i = 0; i < 6; i++) { if (count % columnLimit != 0) { PdfPCell cell = new PdfPCell(new Phrase()); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); count++; } } document.add(table); document.close(); return byteArrayOutputStream; } catch (Exception e) { return null; } }
From source file:org.qnot.passtab.PDFOutput.java
License:Open Source License
private void createPDF(OutputStream out, String[][] array) throws IOException, DocumentException { Document document = new Document(PageSize.LETTER.rotate()); PdfWriter.getInstance(document, out); document.open();//from w ww. j a va 2s .c o m PdfPTable table = new PdfPTable(array[0].length); table.setTotalWidth((float) array.length * PDFOutput.CELL_WIDTH); table.setLockedWidth(true); table.setHorizontalAlignment(Element.ALIGN_CENTER); for (int i = 0; i < array.length; i++) { for (int j = 0; j < array[0].length; j++) { addCell(table, array[i][j], (j % 2) != 0, (i % 2) != 0, j == 0, i == 0); } } document.add(table); document.close(); }
From source file:Output.QuotePDf.java
private PdfPTable shipperInformationTable(String personnelInformation) throws DocumentException { PdfPTable table = new PdfPTable(4); table.setHorizontalAlignment(Element.ALIGN_LEFT); float[] columnWidths = new float[] { 30f, 70f, 20f, 80f }; table.setWidths(columnWidths);//from w w w . j a v a 2 s. co m cell = new PdfPCell(new Phrase("Quote ID:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(quoteID, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Date:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(date, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Company:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(company, textFont)); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Customer:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(customerName, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Email:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(customerEmail, emailTextFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Quote Type:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(status, textFont)); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Quoted By:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(personnelInformation, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Email:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(groupEmail, emailTextFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); return table; }
From source file:Output.QuotePDf.java
private PdfPTable commodityTable() throws DocumentException { PdfPTable table = new PdfPTable(4); table.setHorizontalAlignment(Element.ALIGN_LEFT); float[] columnWidths = new float[] { 55f, 70f, 55f, 65f }; table.setWidths(columnWidths);/*from w w w . ja v a 2s. com*/ cell = new PdfPCell(new Phrase("Port(s) of Load:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(pol, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("via:", labelFont)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(tship, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Port(s) of Discharge:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(pod, textFont)); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Commodity:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(commodityClass, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Handling:", labelFont)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(cargoHandling, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Accompanying:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); if (accessories) { cell = new PdfPCell(new Phrase(accessories_accompanying, textFont)); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("N/A", textFont)); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } cell = new PdfPCell(new Phrase("Description", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(description, textFont)); cell.setColspan(3); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); return table; }