List of usage examples for com.lowagie.text.pdf PdfPCell disableBorderSide
public void disableBorderSide(int side)
From source file:com.qcadoo.mes.deliveries.print.DeliveryReportPdf.java
License:Open Source License
private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName, Entity delivery) {//from ww w .j a v a 2s .c o m DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery, numberService); PdfPCell total = new PdfPCell( new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale), FontUtils.getDejavuRegular7Dark())); total.setColspan(2); total.setHorizontalAlignment(Element.ALIGN_LEFT); total.setVerticalAlignment(Element.ALIGN_MIDDLE); total.setBackgroundColor(null); total.disableBorderSide(Rectangle.RIGHT); total.disableBorderSide(Rectangle.LEFT); total.setBorderColor(ColorUtils.getLineLightColor()); productsTable.addCell(total); for (int i = 2; i < columnsName.size(); i++) { if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY) && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(DeliveredProductFields.DELIVERED_QUANTITY) && columnsName.indexOf(DeliveredProductFields.DELIVERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell(new Phrase( numberService.format(deliveryPricesAndQuantities.getDeliveredCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(DeliveredProductFields.TOTAL_PRICE) && columnsName.indexOf(DeliveredProductFields.TOTAL_PRICE) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getDeliveredTotalPrice()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); productsTable.addCell( new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark())); } else { productsTable.addCell(""); } } }
From source file:com.qcadoo.mes.deliveries.print.OrderReportPdf.java
License:Open Source License
private void addTotalRow(final PdfPTable productsTable, final Locale locale, final List<String> columnsName, Entity delivery) {/*w w w .j a v a 2s .co m*/ DeliveryPricesAndQuantities deliveryPricesAndQuantities = new DeliveryPricesAndQuantities(delivery, numberService); PdfPCell total = new PdfPCell( new Phrase(translationService.translate("deliveries.delivery.report.totalCost", locale), FontUtils.getDejavuRegular7Dark())); total.setColspan(2); total.setHorizontalAlignment(Element.ALIGN_LEFT); total.setVerticalAlignment(Element.ALIGN_MIDDLE); total.setBackgroundColor(null); total.disableBorderSide(Rectangle.RIGHT); total.disableBorderSide(Rectangle.LEFT); total.setBorderColor(ColorUtils.getLineLightColor()); productsTable.addCell(total); for (int i = 2; i < columnsName.size(); i++) { if (columnsName.contains(OrderedProductFields.ORDERED_QUANTITY) && columnsName.indexOf(OrderedProductFields.ORDERED_QUANTITY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedCumulatedQuantity()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(OrderedProductFields.TOTAL_PRICE) && columnsName.indexOf(OrderedProductFields.TOTAL_PRICE) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); productsTable.addCell( new Phrase(numberService.format(deliveryPricesAndQuantities.getOrderedTotalPrice()), FontUtils.getDejavuRegular7Dark())); } else if (columnsName.contains(L_CURRENCY) && columnsName.indexOf(L_CURRENCY) == i) { productsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); productsTable.addCell( new Phrase(deliveriesService.getCurrency(delivery), FontUtils.getDejavuRegular7Dark())); } else { productsTable.addCell(""); } } }
From source file:com.qcadoo.mes.orders.print.OrderReportPdf.java
License:Open Source License
private PdfPCell createCell(String content, int alignment) { PdfPCell cell = new PdfPCell(); float border = 0.2f; cell.setPhrase(new Phrase(content, FontUtils.getDejavuRegular7Dark())); cell.setHorizontalAlignment(alignment); cell.setBorderWidth(border);/*from w w w . j a va 2 s. c o m*/ cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); cell.setPadding(5); return cell; }
From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException { boolean result = false; UnitTrayLabel label = new UnitTrayLabel(); LabelEncoder encoder = new LabelEncoder(label); Image image = encoder.getImage(); int counter = 0; try {/*from w w w . ja v a 2 s . c o m*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("labels.pdf")); document.setPageSize(PageSize.LETTER); document.open(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f); //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); float[] cellWidths = { 30f, 20f, 30f, 20f }; table.setWidths(cellWidths); UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle(); if (taxa == null) { taxa = uls.findAll(); } Iterator<UnitTrayLabel> i = taxa.iterator(); PdfPCell cell = null; PdfPCell cell_barcode = null; // Create two lists of 12 cells, the first 6 of each representing // the left hand column of 6 labels, the second 6 of each // representing the right hand column. // cells holds the text for each label, cells_barcode the barcode. ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12); ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12); for (int x = 0; x < 12; x++) { cells.add(null); cells_barcode.add(null); } int cellCounter = 0; while (i.hasNext()) { // Loop through all of the taxa (unit tray labels) found to print label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each taxon, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page log.debug("Label " + toPrint + " of " + label.getNumberToPrint()); cell = new PdfPCell(); cell.setBorderColor(Color.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); String higherNames = ""; if (label.getTribe().trim().length() > 0) { higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe(); } else { higherNames = label.getFamily() + ": " + label.getSubfamily(); } Paragraph higher = new Paragraph(); higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); higher.add(new Chunk(higherNames)); cell.addElement(higher); Paragraph name = new Paragraph(); Chunk genus = new Chunk(label.getGenus().trim() + " "); genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); Chunk species = new Chunk(label.getSpecificEpithet().trim()); Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>) if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) { if (label.getSpecificEpithet().startsWith("nr. ")) { normal = new Chunk("nr. "); normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); species = new Chunk(label.getSpecificEpithet().trim().substring(4)); species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } String s = ""; if (label.getSubspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim()); if (label.getSubspecificEpithet().contains(".") || label.getSubspecificEpithet().contains("[")) { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } else { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } if (label.getInfraspecificRank().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim()); infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); if (label.getInfraspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim()); infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); if (label.getUnNamedForm().trim().length() > 0) { s = " "; } else { s = ""; } Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim()); unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); name.add(genus); if (normal != null) { name.add(normal); } name.add(species); name.add(subspecies); name.add(infraRank); name.add(infra); name.add(unNamed); cell.addElement(name); Paragraph authorship = new Paragraph(); authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); if (label.getAuthorship() != null && label.getAuthorship().length() > 0) { Chunk c_authorship = new Chunk(label.getAuthorship()); authorship.add(c_authorship); } cell.addElement(authorship); //cell.addElement(new Paragraph(" ")); if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) { Paragraph drawerNumber = new Paragraph(); drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_drawerNumber = new Chunk(label.getDrawerNumber()); drawerNumber.add(c_drawerNumber); cell.addElement(drawerNumber); } else { if (label.getCollection() != null && label.getCollection().length() > 0) { Paragraph collection = new Paragraph(); collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_collection = new Chunk(label.getCollection()); collection.add(c_collection); cell.addElement(collection); } } cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(Color.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); cell_barcode.addElement(image); cells.add(cellCounter, cell); cells_barcode.add(cellCounter, cell_barcode); cellCounter++; // If we have hit a full set of 12 labels, add them to the document // in two columns, filling left column first, then right if (cellCounter == 12) { // add a page of 12 cells in columns of two. for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // Reset to begin next page cellCounter = 0; document.add(table); table = new PdfPTable(4); table.setWidthPercentage(100f); table.setWidths(cellWidths); for (int x = 0; x < 12; x++) { cells.set(x, null); cells_barcode.set(x, null); } } } // end loop through toPrint (for a taxon) counter++; } // end while results has next (for all taxa requested) // get any remaining cells in pairs for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // add any remaining cells document.add(table); try { document.close(); } catch (Exception e) { throw new PrintFailedException("No labels to print." + e.getMessage()); } // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; // Increment number printed. i = taxa.iterator(); while (i.hasNext()) { label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { label.setPrinted(label.getPrinted() + 1); } label.setNumberToPrint(0); try { uls.attachDirty(label); } catch (SaveFailedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("File not found."); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("Error buiding PDF document."); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } return result; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.stylable.StyleUtils.java
License:Open Source License
public static void applyStyles(StyleBorder border, PdfPCell cell) { if (border == null) { return;//w ww.j a v a2 s . c o m } switch (border.getBorderType()) { case ALL: // border if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.TOP); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); } else { cell.enableBorderSide(PdfPCell.TOP); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); // border-color Color color = border.getColor(); if (color != null) { cell.setBorderColor(color); } // border-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidth(width); } } break; case BOTTOM: // border-bottom if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.BOTTOM); } else { cell.enableBorderSide(PdfPCell.BOTTOM); // border-bottom-color Color color = border.getColor(); if (color != null) { cell.setBorderColorBottom(color); } // border-bottom-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthBottom(width); } } break; case LEFT: // border-left if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.LEFT); } else { cell.enableBorderSide(PdfPCell.LEFT); // border-left-color Color color = border.getColor(); if (color != null) { cell.setBorderColorLeft(color); } // border-left-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthLeft(width); } } break; case RIGHT: // border-right if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.RIGHT); } else { cell.enableBorderSide(PdfPCell.RIGHT); // border-right-color Color color = border.getColor(); if (color != null) { cell.setBorderColorRight(color); } // border-right-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthRight(width); } } break; case TOP: // border-top if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.TOP); } else { cell.enableBorderSide(PdfPCell.TOP); // border-top-color Color color = border.getColor(); if (color != null) { cell.setBorderColorTop(color); } // border-top-width Float width = border.getWidth(); if (width != null) { cell.setBorderWidthTop(width); } } break; } }
From source file:org.apache.poi.xwpf.converter.internal.itext.stylable.StyleUtils.java
License:Open Source License
public static void applyStyles(StyleBorder border, PdfPCell cell) { if (border == null) { return;/*from w ww . j a v a 2 s . co m*/ } switch (border.getBorderType()) { case ALL: // border if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.TOP); cell.disableBorderSide(PdfPCell.BOTTOM); cell.disableBorderSide(PdfPCell.RIGHT); cell.disableBorderSide(PdfPCell.LEFT); } else { cell.enableBorderSide(PdfPCell.TOP); cell.enableBorderSide(PdfPCell.BOTTOM); cell.enableBorderSide(PdfPCell.RIGHT); cell.enableBorderSide(PdfPCell.LEFT); // border-color Color color = border.getColor(); if (color != null) { cell.setBorderColor(color); } // border-width BigInteger width = border.getWidth(); if (width != null) { cell.setBorderWidth(dxa2points(width)); } } break; case BOTTOM: // border-bottom if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.BOTTOM); } else { cell.enableBorderSide(PdfPCell.BOTTOM); // border-bottom-color Color color = border.getColor(); if (color != null) { cell.setBorderColorBottom(color); } // border-bottom-width BigInteger width = border.getWidth(); if (width != null) { cell.setBorderWidthBottom(dxa2points(width)); } } break; case LEFT: // border-left if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.LEFT); } else { cell.enableBorderSide(PdfPCell.LEFT); // border-left-color Color color = border.getColor(); if (color != null) { cell.setBorderColorLeft(color); } // border-left-width BigInteger width = border.getWidth(); if (width != null) { cell.setBorderWidthLeft(dxa2points(width)); } } break; case RIGHT: // border-right if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.RIGHT); } else { cell.enableBorderSide(PdfPCell.RIGHT); // border-right-color Color color = border.getColor(); if (color != null) { cell.setBorderColorRight(color); } // border-right-width BigInteger width = border.getWidth(); if (width != null) { cell.setBorderWidthRight(dxa2points(width)); } } break; case TOP: // border-top if (border.isNoBorder()) { cell.disableBorderSide(PdfPCell.TOP); } else { cell.enableBorderSide(PdfPCell.TOP); // border-top-color Color color = border.getColor(); if (color != null) { cell.setBorderColorTop(color); } // border-top-width BigInteger width = border.getWidth(); if (width != null) { cell.setBorderWidthTop(dxa2points(width)); } } break; } }
From source file:org.apache.poi.xwpf.converter.internal.itext.XWPFTableUtil.java
License:Open Source License
public static void setBorder(CTBorder border, PdfPCell pdfPCell, int borderSide) { if (border == null) { return;/* w w w .jav a 2 s. c o m*/ } boolean noBorder = (STBorder.NONE == border.getVal()); // No border if (noBorder) { pdfPCell.disableBorderSide(borderSide); } else { float size = -1; BigInteger borderSize = border.getSz(); if (borderSize != null) { size = dxa2points(borderSize); } Color borderColor = null; String hexColor = getBorderColor(border); if (hexColor != null) { borderColor = ColorRegistry.getInstance().getColor("0x" + hexColor); } switch (borderSide) { case Rectangle.TOP: if (size != -1) { pdfPCell.setBorderWidthTop(size); } if (borderColor != null) { pdfPCell.setBorderColorTop(borderColor); } break; case Rectangle.BOTTOM: if (size != -1) { pdfPCell.setBorderWidthBottom(size); } if (borderColor != null) { pdfPCell.setBorderColorBottom(borderColor); } break; case Rectangle.LEFT: if (size != -1) { pdfPCell.setBorderWidthLeft(size); } if (borderColor != null) { pdfPCell.setBorderColorLeft(borderColor); } break; case Rectangle.RIGHT: if (size != -1) { pdfPCell.setBorderWidthRight(size); } if (borderColor != null) { pdfPCell.setBorderColorRight(borderColor); } break; } } }
From source file:org.revager.export.PDFExporter.java
License:Open Source License
/** * Creates an empty PdfPTable cell with a defined height and colspan. * /*from w w w .j av a 2 s . c o m*/ * @param height * the height of the created cell * @param colspan * the colspan * * @return Empty cell with defined minimum height */ protected PdfPCell createVerticalStrut(float height, int colspan) { PdfPCell fill = new PdfPCell(); fill.setColspan(colspan); fill.setMinimumHeight(height); fill.disableBorderSide(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP | Rectangle.BOTTOM); return fill; }