List of usage examples for com.itextpdf.text Element ALIGN_MIDDLE
int ALIGN_MIDDLE
To view the source code for com.itextpdf.text Element ALIGN_MIDDLE.
Click Source Link
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
private PdfPCell getStringCell(String str, Font font, int border, int align, int colspan) { PdfPCell cell = new PdfPCell(new Paragraph(str, font)); cell.setPaddingTop(5);//from ww w. j ava 2 s. c o m cell.setPaddingBottom(5); cell.setBorderWidth(1); cell.setBorder(border); cell.setHorizontalAlignment(align); cell.setVerticalAlignment(Element.ALIGN_MIDDLE /*.ALIGN_CENTER*/); cell.setColspan(colspan); return cell; }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public void generatePdf(Author author, String filename, String type) { // A4: 8.267in x 11.692in => 595.224units x 841.824units (72units/inch) // marginLeft, marginRight, marginTop, marginBottom Document document = new Document(PageSize.A4, 50, 50, 80, 50); try {//w w w . j av a 2 s . c om if (m_shopping_basket.size() > 0) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); writer.setBoxSize("art", new Rectangle(50, 50, 560, 790)); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); document.open(); PdfContentByte cb = writer.getDirectContent(); document.addAuthor("ywesee GmbH"); document.addCreator("AmiKo for Windows"); document.addCreationDate(); // Logo String logoImageStr = m_prefs.get(LogoImageID, Constants.IMG_FOLDER + "empty_logo.png"); File logoFile = new File(logoImageStr); if (!logoFile.exists()) logoImageStr = Constants.IMG_FOLDER + "empty_logo.png"; Image logo = Image.getInstance(logoImageStr); logo.scalePercent(30); logo.setAlignment(Rectangle.ALIGN_RIGHT); document.add(logo); document.add(Chunk.NEWLINE); // Bestelladresse // --> String bestellAdrStr = m_prefs.get(BestellAdresseID, m_rb.getString("noaddress1")); String bestellAdrStr = getAddressAsString(BestellAdresseID); Paragraph p = new Paragraph(12); // p.setIndentationLeft(60); p.add(new Chunk(bestellAdrStr, font_norm_10)); document.add(p); document.add(Chunk.NEWLINE); // Title p = new Paragraph(m_rb.getString("order"), font_bold_16); document.add(p); // Date DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss"); Date date = new Date(); p = new Paragraph(m_rb.getString("date") + ": " + dateFormat.format(date), font_bold_10); p.setSpacingAfter(20); document.add(p); // document.add(Chunk.NEWLINE); // Add addresses (Lieferadresse + Rechnungsadresse) /* --> OLD String lieferAdrStr = m_prefs.get(LieferAdresseID, m_rb.getString("noaddress2")); String rechnungsAdrStr = m_prefs.get(RechnungsAdresseID, m_rb.getString("noaddress3")); */ // --> NEW String lieferAdrStr = getAddressAsString(LieferAdresseID); String rechnungsAdrStr = getAddressAsString(RechnungsAdresseID); PdfPTable addressTable = new PdfPTable(new float[] { 1, 1 }); addressTable.setWidthPercentage(100f); addressTable.getDefaultCell().setPadding(5); addressTable.setSpacingAfter(5f); addressTable.addCell(getStringCell(m_rb.getString("shipaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell(getStringCell(m_rb.getString("billaddress"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(lieferAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); addressTable.addCell( getStringCell(rechnungsAdrStr, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); document.add(addressTable); document.add(Chunk.NEWLINE); // Add shopping basket if (type.equals("specific")) document.add(getShoppingBasketForAuthor(author, cb)); else if (type.equals("all")) document.add(getFullShoppingBasket(cb, "all")); else if (type.equals("rest")) document.add(getFullShoppingBasket(cb, "rest")); LineSeparator separator = new LineSeparator(); document.add(separator); } } catch (IOException e) { } catch (DocumentException e) { } document.close(); // System.out.println("Saved PDF to " + filename); }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public PdfPTable getShoppingBasketForAuthor(Author a, PdfContentByte cb) { int position = 0; float subtotal_CHF = 0.0f; float shipping_CHF = 0.0f; float vat25_CHF = 0.0f; float vat80_CHF = 0.0f; String author = a.getShortName(); BarcodeEAN codeEAN = new BarcodeEAN(); // Pos | Menge | Eancode | Bezeichnung | MwSt | Preis PdfPTable table = new PdfPTable(new float[] { 1, 2, 3, 6, 1, 2 }); table.setWidthPercentage(100f);//ww w.j ava2 s . c om table.getDefaultCell().setPadding(5); table.setSpacingAfter(5f); PdfPCell cell = new PdfPCell(); table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("vat"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1)); table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1)); if (m_shopping_basket.size() > 0 && !author.isEmpty()) { for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) { Article article = entry.getValue(); if (article.getAuthor().trim().toLowerCase().contains(author)) { String price_pruned = ""; String total_price_CHF = ""; if (article.getCode() != null && article.getCode().equals("ibsa")) { float cr = article.getCashRebate(); if (article.getDraufgabe() > 0) { price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f)); total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(0.0f)); } else { price_pruned = String.format("%.2f", article.getBuyingPrice(cr)); total_price_CHF = String.format("%.2f", article.getTotBuyingPrice(cr)); } } else { price_pruned = article.getCleanExfactoryPrice(); total_price_CHF = String.format("%.2f", article.getTotExfactoryPrice()); } if (!price_pruned.isEmpty() && !price_pruned.equals("..")) { // Index table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); // Anzahl table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); // EAN code codeEAN.setCode(article.getEanCode()); Image img = codeEAN.createImageWithBarcode(cb, null, null); img.scalePercent(120); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setUseBorderPadding(true); cell.setBorderWidth(5); if (position == 1) cell.setPaddingTop(8); else cell.setPaddingTop(0); cell.setPaddingBottom(8); table.addCell(cell); // Artikelbezeichnung table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); // MwSt table.addCell(getStringCell(String.format("%.1f%%", article.getVat()), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1)); // Preis (exkl. MwSt) // float price_CHF = article.getQuantity()*Float.parseFloat(price_pruned); table.addCell(getStringCell(total_price_CHF, font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1)); } } } subtotal_CHF = a.getSubtotal(); shipping_CHF = a.getShippingCosts(); vat25_CHF = a.getVat25(); vat80_CHF = a.getVat80() + a.getShippingCosts() * 0.08f; float fulltotal_CHF = subtotal_CHF + shipping_CHF + vat25_CHF + vat80_CHF; table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", subtotal_CHF), font_bold_10, Rectangle.TOP, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("shipping"), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", shipping_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", vat25_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("vat") + " (8.0%)", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", vat80_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", fulltotal_CHF), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); } return table; }
From source file:com.maxl.java.amikodesk.SaveBasket.java
License:Open Source License
public PdfPTable getFullShoppingBasket(PdfContentByte cb, String mode) { int position = 0; float sub_total_CHF = 0.0f; BarcodeEAN codeEAN = new BarcodeEAN(); // Pos | Menge | Eancode | Bezeichnung | Preis PdfPTable table = new PdfPTable(new float[] { 1, 1, 3, 6, 2 }); table.setWidthPercentage(100f);//from w w w . j a va2 s . c o m table.getDefaultCell().setPadding(5); table.setSpacingAfter(5f); PdfPCell cell = new PdfPCell(); table.addCell(getStringCell(m_rb.getString("position"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("quantity"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("ean"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("article"), font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(m_rb.getString("price") + " (CHF)", font_bold_10, Rectangle.TOP | Rectangle.BOTTOM, Element.ALIGN_RIGHT, 1)); if (m_shopping_basket.size() > 0) { for (Map.Entry<String, Article> entry : m_shopping_basket.entrySet()) { Article article = entry.getValue(); if (mode.equals("all") || (mode.equals("rest") && (m_map_of_authors == null || !anyElemIsContained(m_map_of_authors, article.getAuthor().trim().toLowerCase())))) { String price_pruned = ""; if (article.getCode() != null && article.getCode().equals("ibsa")) { float cr = article.getCashRebate(); if (article.getDraufgabe() > 0) price_pruned = String.format("%.2f", article.getBuyingPrice(0.0f)); else price_pruned = String.format("%.2f", article.getBuyingPrice(cr)); } else { price_pruned = article.getCleanExfactoryPrice(); } if (!price_pruned.isEmpty() && !price_pruned.equals("..")) { table.addCell(getStringCell(Integer.toString(++position), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); table.addCell(getStringCell(Integer.toString(article.getQuantity()), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); codeEAN.setCode(article.getEanCode()); Image img = codeEAN.createImageWithBarcode(cb, null, null); img.scalePercent(120); cell = new PdfPCell(img); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setUseBorderPadding(true); cell.setBorderWidth(5); if (position == 1) cell.setPaddingTop(8); else cell.setPaddingTop(0); cell.setPaddingBottom(8); table.addCell(cell); table.addCell(getStringCell(article.getPackTitle(), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 1)); float price_CHF = article.getQuantity() * Float.parseFloat(price_pruned); sub_total_CHF += price_CHF; table.addCell(getStringCell(String.format("%.2f", price_CHF), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 1)); } } } table.addCell(getStringCell(m_rb.getString("subtotal"), font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, Rectangle.TOP, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", sub_total_CHF), font_bold_10, Rectangle.TOP, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("vat") + " (2.5%)", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 0.025f), font_norm_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); table.addCell(getStringCell(m_rb.getString("gesamttotal"), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell("", font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_MIDDLE, 2)); table.addCell(getStringCell(String.format("%.2f", sub_total_CHF * 1.025f), font_bold_10, PdfPCell.NO_BORDER, Element.ALIGN_RIGHT, 2)); } return table; }
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
private void setTableHeader(String value, PdfPTable table) { PdfPCell cell = new PdfPCell(new Paragraph(value)); cell.setBorderColor(BaseColor.GRAY); cell.setFixedHeight(25);/*from w w w. j av a 2 s. c om*/ BaseColor myColor = WebColors.getRGBColor("#F7F7F7"); cell.setBackgroundColor(myColor); cell.setPaddingLeft(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); }
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
private void setTableContent(String value, PdfPTable table) { PdfPCell cell = new PdfPCell(new Paragraph(value)); cell.setBorderColor(BaseColor.GRAY); cell.setPaddingLeft(10);/*from www . j av a2 s .c om*/ cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); }
From source file:com.norbsoft.pdfconverter.helpers.PDFHelper.java
License:Open Source License
private PdfPTable table(Form form) { int cellPadding = 5; PdfPTable table = new PdfPTable(8); table.setSpacingBefore(20);//from w w w . jav a 2 s .c o m try { table.setWidths(new int[] { 100, 120, 30, 60, 60, 50, 50, 50 }); } catch (DocumentException e) { Log.e(TAG, "Width error:" + e.getMessage()); } PdfPCell cell = new PdfPCell(new Paragraph("Adres: " + form.getAddress(), normal)); cell.setColspan(8); cell.setPadding(cellPadding); cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Paragraph("Odbiorca: " + form.getOwner(), normal)); cell.setColspan(8); cell.setPadding(cellPadding); cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Paragraph("Data: " + form.getDate(), normal)); cell.setColspan(3); cell.setPadding(cellPadding); cell.setBorder(Rectangle.LEFT | Rectangle.BOTTOM); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Paragraph("tel: " + form.getPhone(), normal)); cell.setColspan(5); cell.setPadding(cellPadding); cell.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); //Header Paragraph p = new Paragraph("WODOMIERZ", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setNoWrap(true); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Nr fabryczny", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("DN", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Typ\r\nProducent", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Stan w (m3)", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Rok\r\nlegalizacji", bold); cell = new PdfPCell(p); ; cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Czy plomba\r\nlegalizacyjna jest\r\nuszkodzona?", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); //First row cell = new PdfPCell(new Paragraph("Zamontowany", bold)); cell.setNoWrap(true); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getNewSN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewDN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewType() + "\r\n" + form.getNewManufacturer(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewState(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewYear(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getNewSeal().equals("Tak")) p = new Paragraph("tak", normal); else p = new Paragraph("tak", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getNewSeal().equals("Nie")) p = new Paragraph("nie", normal); else p = new Paragraph("nie", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); //Second row cell = new PdfPCell(new Paragraph("Wymontowany", bold)); cell.setNoWrap(true); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getOldSN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldDN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldType() + "\r\n" + form.getOldManufacturer(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldState(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldYear(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getOldSeal().equals("Tak")) p = new Paragraph("tak", normal); else p = new Paragraph("tak", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getOldSeal().equals("Nie")) p = new Paragraph("nie", normal); else p = new Paragraph("nie", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); //Third row cell = new PdfPCell(new Paragraph("Plomba nr 1", bold)); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getSealFirst(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph("Przyczyna wymiany: " + form.getReason(), normal)); cell.setPadding(cellPadding); cell.setColspan(5); table.addCell(cell); //Fourth row cell = new PdfPCell(new Paragraph("Plomba nr 2", bold)); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getSealSecond(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph("Umiejscowienie wodomierza: " + form.getPlacement(), normal)); cell.setPadding(cellPadding); cell.setColspan(5); table.addCell(cell); //Fourth row cell = new PdfPCell(new Paragraph("Nr moduu\r\nradiowego", bold)); cell.setPadding(cellPadding); table.addCell(cell); cell = new PdfPCell(new Paragraph(form.getNewModuleNumber(), normal)); cell.setPadding(cellPadding); cell.setColspan(7); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); table.setWidthPercentage(100); return table; }
From source file:com.pearson.controller.PdfGentrate.java
public static void main(String[] args) { try {/*from www.j av a 2s . c o m*/ /*Document document = new Document(PageSize. A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance (document, new FileOutputStream("C:\\my.pdf")); document.open(); // create a chunk object using chunk class of itext library. Chunk underlined = new Chunk("Welcome to Pearson Q-Service Portal : "); // set the distance between text and line. underlined.setTextRise(8.0f); // set the width of the line, 'y' position, color and design of the line underlined.setUnderline(new Color(0x00, 0x00, 0xFF),0.0f, 0.2f, 3.0f, 0.0f, PdfContentByte.LINE_CAP_PROJECTING_SQUARE); // finally add object to the document. document.add(underlined); document.add(new Paragraph("Hi username", FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD, new Color(255, 150, 200))));; document.add(new Paragraph("Tiltle",catFont)); document.add(new Paragraph("Report generated by: " + System.getProperty("user.name") + ", " + new Date(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ smallBold)); document.add(new Paragraph("This document is a preliminary version and not subject to your license agreement or any other agreement with vogella.com ;-).", redFont)); PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = {1f, 1f, 1f}; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); cell1.setBorderColor(BaseColor.BLUE); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); cell2.setBorderColor(BaseColor.GREEN); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); cell3.setBorderColor(BaseColor.RED); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); //To avoid having the cell border and the content overlap, if you are having thick cell borders //cell1.setUserBorderPadding(true); //cell2.setUserBorderPadding(true); //cell3.setUserBorderPadding(true); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); document.add(table); document.close(); writer.close(); document.close(); } catch (Exception e2) { System.out.println(e2.getMessage()); } }*/ Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("AddTableExample.pdf")); document.open(); PdfPTable table = new PdfPTable(3); // 3 columns. table.setWidthPercentage(100); //Width 100% table.setSpacingBefore(10f); //Space before table table.setSpacingAfter(10f); //Space after table //Set Column widths float[] columnWidths = { 1f, 1f, 1f }; table.setWidths(columnWidths); PdfPCell cell1 = new PdfPCell(new Paragraph("Cell 1")); cell1.setBorderColor(BaseColor.BLUE); cell1.setPaddingLeft(10); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); cell1.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell2 = new PdfPCell(new Paragraph("Cell 2")); cell2.setBorderColor(BaseColor.GREEN); cell2.setPaddingLeft(10); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell3 = new PdfPCell(new Paragraph("Cell 3")); cell3.setBorderColor(BaseColor.RED); cell3.setPaddingLeft(10); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); cell3.setVerticalAlignment(Element.ALIGN_MIDDLE); //To avoid having the cell border and the content overlap, if you are having thick cell borders //cell1.setUserBorderPadding(true); //cell2.setUserBorderPadding(true); //cell3.setUserBorderPadding(true); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); document.add(table); document.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.planning.project.controller.CreatePDF.java
private static void createTable(Document document) throws DocumentException, IOException { Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); font.setSize(16);// w w w . j a va 2s . c o m Paragraph paragraph = new Paragraph(); paragraph.setFont(font); creteEmptyLine(paragraph, 2); document.add(paragraph); PdfPTable table = new PdfPTable(7); paragraph.add(""); PdfPCell c1 = new PdfPCell(new Phrase("asasas", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("/?", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("?", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); TbActivity ac = new TbActivity(); c1 = new PdfPCell(new Phrase("", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("", font)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); paragraph.add(""); for (int i = 0; i < 7; i++) { table.setWidthPercentage(100); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(paragraph); } document.add(table); }
From source file:com.planning.project.controller.CreatePDF.java
public static PdfPTable createtableTargetGroup(TbTargetgroup targetGroup) throws DocumentException, Exception { Font font = new Font(BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); font.setSize(16);//from w ww .j a va2 s.co m PdfPTable table = new PdfPTable(3); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); PdfPCell cell = new PdfPCell(new Phrase("? ", font)); cell.setColspan(5); table.addCell(cell); cell = new PdfPCell(new Phrase("", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("?()", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase( " ()", font)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); table.addCell(new PdfPCell(new Phrase("", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutMana(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinMana(), font))); table.addCell(new PdfPCell(new Phrase("", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutTeach(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinTeach(), font))); table.addCell(new PdfPCell(new Phrase("", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutEmp(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinEmp(), font))); table.addCell(new PdfPCell(new Phrase("??", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutStu(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinStu(), font))); table.addCell(new PdfPCell(new Phrase("/?", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutCommu(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinCommu(), font))); table.addCell( new PdfPCell(new Phrase("?/?", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutDisable(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinDisable(), font))); table.addCell(new PdfPCell(new Phrase("", font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJooutOther(), font))); table.addCell(new PdfPCell(new Phrase(targetGroup.getJoinOther(), font))); return table; }