/** * Adds the report title for balanced report. * * @param document * the report document. * @param reportName * the report name. * @param fiscalYear * the fiscal year. * @param quarter * the quarter. * @param startDate * the start date. * @param endDate * the end date. * @throws com.itextpdf.text.DocumentException * if any error occurs. */ static void addBalancedReportTitle(com.itextpdf.text.Document document, String reportName, Integer fiscalYear, Integer quarter, Date startDate, Date endDate) throws com.itextpdf.text.DocumentException { com.itextpdf.text.Paragraph title = new com.itextpdf.text.Paragraph(reportName, new Font(FontFamily.HELVETICA, 16, Font.BOLD)); title.setAlignment(PDF_ALIGN_CENTER); document.add(title); if (fiscalYear != null && quarter != null) { com.itextpdf.text.Paragraph subTitle1 = new com.itextpdf.text.Paragraph("Fiscal Year " + fiscalYear + " - Quarter" + quarter, new Font(FontFamily.HELVETICA, 14, Font.BOLD)); subTitle1.setAlignment(PDF_ALIGN_CENTER); document.add(subTitle1); } if (startDate != null && endDate != null) { com.itextpdf.text.Paragraph subTitle2 = new com.itextpdf.text.Paragraph("Processed between " + "" + REPORT_DATE_FORMAT.format(startDate) + " and " + "" + REPORT_DATE_FORMAT.format(endDate), new Font(FontFamily.HELVETICA, 12, Font.BOLD)); subTitle2.setAlignment(PDF_ALIGN_CENTER); document.add(subTitle2); } }
/** * This method creates a PDF with a single styled paragraph. */ static byte[] createSimpleTextPdf() throws DocumentException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter.getInstance(document, baos); document.open(); Paragraph paragraph = new Paragraph(); paragraph.add(new Phrase("Beware: ", new Font(FontFamily.HELVETICA, 12, Font.BOLDITALIC))); paragraph.add(new Phrase("The implementation of ", new Font(FontFamily.HELVETICA, 12, Font.ITALIC))); paragraph.add(new Phrase("MarginFinder", new Font(FontFamily.COURIER, 12, Font.ITALIC))); paragraph.add(new Phrase(" is far from optimal. It is not even correct as it includes all curve control points which is too much. Furthermore it ignores stuff like line width or wedge types. It actually merely is a proof-of-concept.", new Font(FontFamily.HELVETICA, 12, Font.ITALIC))); document.add(paragraph); document.close(); return baos.toByteArray(); }
public void createPdf(String filename) throws DocumentException, IOException { Document document = new Document(PageSize.LETTER); PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); // step 4 - add content into document for (int i = 0; i < 5; i++) { document.add(new Phrase("Hello", new Font(FontFamily.HELVETICA, 32, Font.BOLD))); document.add(new Phrase("World", new Font(FontFamily.COURIER, 40, Font.ITALIC))); document.add(new Phrase("!!!", new Font(FontFamily.TIMES_ROMAN, 40))); document.add(Chunk.NEWLINE); } document.close(); }
public void createPdf(String filename) throws DocumentException, IOException { Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); // TODO: 1. get direct content PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(FontFamily.HELVETICA, 18, Font.BOLD, BaseColor.ORANGE); Phrase headerText = new Phrase("PSEG DP&C", font); int alignLeft = Element.ALIGN_LEFT; float right = document.getPageSize().getRight(); float top = document.getPageSize().getTop(); // TODO: 2. use ColumnText ColumnText.showTextAligned(canvas, alignLeft, headerText, right - 180, top - 36, 0); document.close(); }
public HeaderFooter(int maximumPageNumber) { _maximumPageNumber = maximumPageNumber; Chunk c = new Chunk("" + (char) 229); c.setFont(new Font(FontFamily.SYMBOL, 28)); _sumSymbol = new Phrase(c); }
private void pageNumberFooter(PdfWriter writer, Rectangle rect) { Chunk c = new Chunk(String.format(LocaleStrings.getString("page"), writer.getPageNumber(), _maximumPageNumber)); c.setFont(new Font(FontFamily.HELVETICA, 10)); Phrase pagephrase = new Phrase(c); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, pagephrase, rect.getRight() - 60, rect.getBottom() - 30, 0); }
/** * <a href="http://stackoverflow.com/questions/34681893/itextsharp-extra-space-between-lines"> * iTextSharp: Extra space between lines * </a> * <p> * Indeed, the OP's {@link Phrase#setLeading(float, float)} calls are ignored. * The reason is that the op is working in text mode. Thus, he has to use * {@link ColumnText#setLeading(float, float)} instead, cf. * {@link #testLikeUser3208131Fixed()}. * </p> */ @Test public void testLikeUser3208131() throws DocumentException, FileNotFoundException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "interline-user3208131.pdf"))); document.open(); Font font = new Font(FontFamily.UNDEFINED, 4, Font.UNDEFINED, null); PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); float gutter = 15; float colwidth = (document.getPageSize().getRight() - document.getPageSize().getLeft() - gutter) / 2; float[] left = { document.getPageSize().getLeft() + 133, document.getPageSize().getTop() - 35, document.getPageSize().getLeft() + 133, document.getPageSize().getBottom() }; float[] right = { document.getPageSize().getLeft() + colwidth, document.getPageSize().getTop() - 35, document.getPageSize().getLeft() + colwidth, document.getPageSize().getBottom() }; for (int i = 0; i < 3; i++) { Phrase Ps = new Phrase("Test " + i + "\n", font); Ps.setLeading(0.0f, 0.6f); ct.addText(Ps); ct.addText(Chunk.NEWLINE); } ct.setColumns(left, right); ct.go(); document.close(); }
/** * <a href="http://stackoverflow.com/questions/34681893/itextsharp-extra-space-between-lines"> * iTextSharp: Extra space between lines * </a> * <p> * Indeed, the OP's {@link Phrase#setLeading(float, float)} calls are ignored, * cf. {@link #testLikeUser3208131()}. The reason is that the op is working in * text mode. Thus, he has to use {@link ColumnText#setLeading(float, float)} * instead. * </p> */ @Test public void testLikeUser3208131Fixed() throws DocumentException, FileNotFoundException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(new File(RESULT_FOLDER, "interline-user3208131-fixed.pdf"))); document.open(); Font font = new Font(FontFamily.UNDEFINED, 4, Font.UNDEFINED, null); PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); float gutter = 15; float colwidth = (document.getPageSize().getRight() - document.getPageSize().getLeft() - gutter) / 2; float[] left = { document.getPageSize().getLeft() + 133, document.getPageSize().getTop() - 35, document.getPageSize().getLeft() + 133, document.getPageSize().getBottom() }; float[] right = { document.getPageSize().getLeft() + colwidth, document.getPageSize().getTop() - 35, document.getPageSize().getLeft() + colwidth, document.getPageSize().getBottom() }; ct.setLeading(0.0f, 0.3f); for (int i = 0; i < 3; i++) { Phrase Ps = new Phrase("Test " + i + "\n", font); ct.addText(Ps); ct.addText(Chunk.NEWLINE); } ct.setColumns(left, right); ct.go(); document.close(); }
/** * <a href="http://stackoverflow.com/questions/31980979/itext-importing-styled-text-and-informations-from-an-existing-pdf"> * iText: Importing styled Text and informations from an existing PDF * </a> * <p> * This method demonstrates how to import merely the region of a PDF page with * actual content. The main necessity is to call {@link #cropPdf(PdfReader)} * for the reader in question which restricts the media boxes of the pages to * the bounding box of the existing content. * </p> */ @Test public void testImportPages() throws DocumentException, IOException { byte[] docText = createSimpleTextPdf(); Files.write(new File(RESULT_FOLDER, "textOnly.pdf").toPath(), docText); byte[] docGraphics = createSimpleCircleGraphicsPdf(); Files.write(new File(RESULT_FOLDER, "graphicsOnly.pdf").toPath(), docGraphics); PdfReader readerText = new PdfReader(docText); cropPdf(readerText); PdfReader readerGraphics = new PdfReader(docGraphics); cropPdf(readerGraphics); try ( FileOutputStream fos = new FileOutputStream(new File(RESULT_FOLDER, "importPages.pdf"))) { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, fos); document.open(); document.add(new Paragraph("Let's import 'textOnly.pdf'", new Font(FontFamily.HELVETICA, 12, Font.BOLD))); document.add(Image.getInstance(writer.getImportedPage(readerText, 1))); document.add(new Paragraph("and now 'graphicsOnly.pdf'", new Font(FontFamily.HELVETICA, 12, Font.BOLD))); document.add(Image.getInstance(writer.getImportedPage(readerGraphics, 1))); document.add(new Paragraph("That's all, folks!", new Font(FontFamily.HELVETICA, 12, Font.BOLD))); document.close(); } finally { readerText.close(); readerGraphics.close(); } }
public static void createHeaderBlock(PdfContentByte cb, int pageNumber, int pageSize) throws DocumentException, IOException { cb.saveState(); cb.setColorFill(BaseColor.BLACK); cb.rectangle(0.0f, 822.0f, 595.0f, 20.0f); cb.fill(); cb.stroke(); cb.restoreState(); Font textFont = new Font(FontFamily.HELVETICA, 7, Font.NORMAL, BaseColor.WHITE); PdfPTable table = new PdfPTable(4); float[] rows = { 100f, 100f, 100f, 295f }; table.setTotalWidth(rows); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setFixedHeight(20); table.addCell(new Phrase(new Chunk("WALD 1.1 gGmbH", textFont))); table.addCell(new Phrase(new Chunk("[ Spendenkonto 222 888 ]", textFont))); table.addCell(new Phrase(new Chunk("www.iplantatree.org", textFont))); PdfPCell pageCell = new PdfPCell(new Phrase(new Chunk("Seite " + pageNumber + " von " + pageSize, textFont))); pageCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); pageCell.setBorder(PdfPCell.NO_BORDER); table.addCell(pageCell); table.writeSelectedRows(0, 1, 0, 842, cb); }
public static void createAdress(PdfContentByte cb, float xCoord, float yCoord) throws DocumentException { Font textFontForAdress = new Font(FontFamily.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK); PdfPTable table = new PdfPTable(1); float[] rows = { 200f }; table.setTotalWidth(rows); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setFixedHeight(14f); table.addCell(new Phrase(new Chunk("Wald 1.1 gemeinnützige GmbH", textFontForAdress))); table.addCell(new Phrase(new Chunk("Gabelsbergerstraße 4", textFontForAdress))); table.addCell(new Phrase(new Chunk("D-06114 Halle", textFontForAdress))); table.writeSelectedRows(0, 3, xCoord, yCoord, cb); }
public static void main(String[] args) throws Exception{ FileOutputStream out = new FileOutputStream("demo.pdf"); //Rectangle rectangle = new Rectangle(216f, 720f); //Document document = new Document(rectangle, 36f, 72f, 108f, 180f); Document document = new Document(PageSize.A4); //document.setPageSize(PageSize.B5); //document.setMarginMirroring(true); //document.setMarginMirroringTopBottom(true); //BaseFont msyh = BaseFont.createFont("src/main/resources/com/hg/ecommerce/util/SIMSUNB.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); BaseFont msyh = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); PdfWriter writer = PdfWriter.getInstance(document, out); writer.setCloseStream(false); //writer.setUserunit(100f); document.open(); document.add(new Paragraph("Hello World!")); document.add(new Chunk("中国",new Font(msyh,12,Font.BOLD))); document.add(new Chunk(" ")); Font font = new Font(FontFamily.HELVETICA, 6, Font.BOLD, BaseColor.WHITE); Chunk chunk = new Chunk("+86",font); chunk.setBackground(BaseColor.BLACK, 1f, 0.5f, 1f, 1.5f); chunk.setTextRise(6f); document.add(chunk); document.add(Chunk.NEWLINE); document.close(); out.close(); }
public Document generate() { Document document = new Document(); PdfWriter writer; try { writer = PdfWriter.getInstance(document, new FileOutputStream(this.path)); document.open(); PdfContentByte cb = writer.getDirectContent(); // Title document.add(new Paragraph("NPL Kitchen Barcodes: DateTime ????", new Font(FontFamily.TIMES_ROMAN, 20))); // Barcode Table int cols = 3; PdfPTable framing = new PdfPTable(cols); framing.setSpacingBefore(50); framing.setComplete(true); for(int i = 0; i < this.captions.size(); i++) { PdfPTable table = this.createBarcodeTable(cb, captions.get(i), details.get(i), codes.get(i)); PdfPCell cell = new PdfPCell(table); cell.setVerticalAlignment(Element.ALIGN_CENTER); framing.addCell(cell); } for(int i = 0; i < cols - (this.captions.size() % cols); i++) { // fill last row framing.addCell(""); } document.add(framing); document.close(); } catch (FileNotFoundException | DocumentException e) { e.printStackTrace(); } return document; }
/** * Adds a title paragraph to the PDF document. * * @param document * the document. * @param title * the title text. * @throws com.itextpdf.text.DocumentException * if any error occurs. */ static void addReportTitle(com.itextpdf.text.Document document, String title) throws com.itextpdf.text.DocumentException { if (Helper.isNullOrEmpty(title)) { return; } com.itextpdf.text.Paragraph p = new com.itextpdf.text.Paragraph(title, new Font(FontFamily.HELVETICA, 16, Font.BOLD)); p.setAlignment(PDF_ALIGN_CENTER); document.add(p); }
public void createPdf(String filename) throws DocumentException, IOException { Document document = new Document(PageSize.LETTER); PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); // step 4 - add content into document for (int i = 0; i < 5; i++) { document.add(new Paragraph("Hello World !", new Font(FontFamily.HELVETICA, 32, Font.BOLD))); } document.close(); }
protected void buildPdfDocument( Map<String, Object> model, Document document, PdfWriter writer, HttpServletRequest req, HttpServletResponse resp) throws Exception { // Get data "articles" from model @SuppressWarnings("unchecked") List<HrmsLogin> users = (List<HrmsLogin>) model.get("allUsers"); // Fonts Font fontTitle = new Font(FontFamily.TIMES_ROMAN, 14, Font.BOLD, BaseColor.BLACK); Font fontTag = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.WHITE); for(HrmsLogin user: users){ // 1.Title document.add(new Chunk("Employee ID: ")); Chunk title = new Chunk(user.getHrmsEmployeeDetails().getEmpId()+"", fontTitle); document.add(title); document.add(new Chunk(" ")); // -- newline document.add(Chunk.NEWLINE); // 2.URL document.add(new Chunk("Username: ")); Chunk title2 = new Chunk(user.getUsername(), fontTitle); document.add(title2); document.add(new Chunk(" ")); // -- newline document.add(Chunk.NEWLINE); // 3.Categories document.add(new Chunk("Password: ")); Chunk title3 = new Chunk(user.getPassword(), fontTitle); document.add(title3); document.add(new Chunk(" ")); // -- newline document.add(Chunk.NEWLINE); // 4.Tags document.add(new Chunk("Employee ID: ")); Chunk title4 = new Chunk(user.getRole(), fontTitle); document.add(title4); document.add(new Chunk(" ")); // -- newline document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); } }
public static PdfPTable getFooterTable(int x, int y) { java.util.Date date = new java.util.Date(); SimpleDateFormat sdf = new SimpleDateFormat("dd MMM yyyy"); String month = sdf.format(date); System.out.println("Month : " + month); PdfPTable table = new PdfPTable(1); table.setTotalWidth(120); table.setLockedWidth(true); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.TOP); table.getDefaultCell().setBorder(Rectangle.LEFT); table.getDefaultCell().setBorder(Rectangle.RIGHT); table.getDefaultCell().setBorderColorTop(BaseColor.BLUE); table.getDefaultCell().setBorderColorLeft(BaseColor.BLUE); table.getDefaultCell().setBorderColorRight(BaseColor.BLUE); table.getDefaultCell().setBorderWidthTop(1f); table.getDefaultCell().setBorderWidthLeft(1f); table.getDefaultCell().setBorderWidthRight(1f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); Font font1 = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.BLUE); table.addCell(new Phrase("CONTROLLED COPY", font1)); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.LEFT); table.getDefaultCell().setBorder(Rectangle.RIGHT); table.getDefaultCell().setBorderColorLeft(BaseColor.BLUE); table.getDefaultCell().setBorderColorRight(BaseColor.BLUE); table.getDefaultCell().setBorderWidthLeft(1f); table.getDefaultCell().setBorderWidthRight(1f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); Font font = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.RED); table.addCell(new Phrase(month, font)); table.getDefaultCell().setFixedHeight(20); table.getDefaultCell().setBorder(Rectangle.LEFT); table.getDefaultCell().setBorder(Rectangle.RIGHT); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setBorderColorLeft(BaseColor.BLUE); table.getDefaultCell().setBorderColorRight(BaseColor.BLUE); table.getDefaultCell().setBorderColorBottom(BaseColor.BLUE); table.getDefaultCell().setBorderWidthLeft(1f); table.getDefaultCell().setBorderWidthRight(1f); table.getDefaultCell().setBorderWidthBottom(1f); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase("BLR DESIGN DEPT.", font1)); return table; }
private void createBlueBlock(PdfContentByte cb, int treeCount) throws DocumentException { cb.saveState(); cb.setRGBColorFill(0x64, 0xA7, 0xBD); cb.rectangle(0.0f, 375.0f, 595.0f, 200.0f); cb.fill(); cb.stroke(); cb.restoreState(); Font textFont = new Font(FontFamily.TIMES_ROMAN, 14, Font.ITALIC, BaseColor.WHITE); Font textBlack = new Font(FontFamily.TIMES_ROMAN, 14, Font.ITALIC, BaseColor.BLACK); Font textFontTreeCount = new Font(FontFamily.HELVETICA, 30, Font.BOLD, BaseColor.BLACK); PdfPTable tableForTreeCount = new PdfPTable(1); float[] rows = { 495f }; tableForTreeCount.setTotalWidth(rows); tableForTreeCount.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableForTreeCount.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); tableForTreeCount.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); tableForTreeCount.getDefaultCell().setFixedHeight(40); Integer treeCountAsObject = treeCount; tableForTreeCount.addCell(new Phrase(new Chunk(treeCountAsObject.toString(), textFontTreeCount))); tableForTreeCount.writeSelectedRows(0, 1, 50f, 575f, cb); PdfPTable tableForWhiteText = new PdfPTable(1); tableForWhiteText.setTotalWidth(rows); tableForWhiteText.getDefaultCell().setBorder(Rectangle.BOTTOM); tableForWhiteText.getDefaultCell().setBorderWidth(1f); tableForWhiteText.getDefaultCell().setBorderColor(BaseColor.WHITE); tableForWhiteText.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); tableForWhiteText.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); tableForWhiteText.getDefaultCell().setFixedHeight(40); Phrase phraseForTreesPlantForYou = new Phrase(); if (treeCount == 1) { phraseForTreesPlantForYou.add(new Chunk("Baum wurde für Sie gepflanzt!", textFont)); } else { phraseForTreesPlantForYou.add(new Chunk("Bäume wurden für Sie gepflanzt!", textFont)); } PdfPCell longTextCell = new PdfPCell(); longTextCell.setHorizontalAlignment(Element.ALIGN_LEFT); longTextCell.setVerticalAlignment(Element.ALIGN_MIDDLE); longTextCell.setBorder(Rectangle.BOTTOM); longTextCell.setBorderWidth(1f); longTextCell.setBorderColor(BaseColor.WHITE); longTextCell.setFixedHeight(65); Paragraph longText = new Paragraph(new Chunk( "Mit diesem Gutschein können sie Ihre Pflanzung in Augenschein nehmen und mehr über die naturnahen Aufforstungsprojekte bei \"I Plant A Tree\" erfahren. Ihre Bäume wachsen auf ehemals brachliegenden Flächen und sind Teil neu entstehender Wälder.", textFont)); longText.setLeading(15f); longTextCell.addElement(longText); tableForWhiteText.addCell(phraseForTreesPlantForYou); tableForWhiteText.addCell(longTextCell); tableForWhiteText.writeSelectedRows(0, 2, 50f, 535f, cb); PdfPTable tableForHowItWorks = new PdfPTable(1); tableForHowItWorks.setTotalWidth(rows); tableForHowItWorks.getDefaultCell().setBorder(Rectangle.NO_BORDER); tableForHowItWorks.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); tableForHowItWorks.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); tableForHowItWorks.getDefaultCell().setFixedHeight(40); tableForHowItWorks.addCell(new Phrase(new Chunk("Und so einfach funktioniert's:", textBlack))); tableForHowItWorks.writeSelectedRows(0, 2, 50f, 425f, cb); }
private void createTreeCountAndCustomTextBlock(PdfContentByte cb, String customText, int treeCount) throws DocumentException { Font textFont = new Font(FontFamily.TIMES_ROMAN, 16, Font.ITALIC, BaseColor.BLACK); Font textFontTreeCount = new Font(FontFamily.HELVETICA, 30, Font.BOLD, BaseColor.BLACK); Font customTextFont = new Font(FontFamily.HELVETICA, 12, Font.NORMAL, BaseColor.BLACK); cb.saveState(); cb.setRGBColorFill(0xE0, 0xDE, 0xDF); cb.rectangle(0.0f, 325.0f, 595.0f, 205.0f); cb.fill(); cb.stroke(); cb.restoreState(); Integer treeCountAsObj = treeCount; PdfPTable table = new PdfPTable(1); float[] rows = { 595f }; table.setTotalWidth(rows); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setFixedHeight(35); table.addCell(new Phrase(new Chunk("über die Pflanzung von", textFont))); table.addCell(new Phrase(new Chunk(treeCountAsObj.toString(), textFontTreeCount))); table.addCell(new Phrase(new Chunk("Bäumen", textFont))); table.writeSelectedRows(0, 3, 0, 520, cb); cb.saveState(); cb.setRGBColorFill(0xF7, 0xF2, 0xF4); cb.rectangle(50.0f, 345.0f, 495.0f, 60.0f); cb.fill(); cb.stroke(); cb.restoreState(); PdfPTable textTable = new PdfPTable(1); float[] textRows = { 475f }; textTable.setTotalWidth(textRows); textTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); textTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); textTable.getDefaultCell().setFixedHeight(40); textTable.addCell(new Phrase(new Chunk(customText, customTextFont))); textTable.writeSelectedRows(0, 1, 60, 395, cb); }
private void createLawTextDateAndSignatureBlock(PdfContentByte cb, String number, String date) throws DocumentException, MalformedURLException, IOException { Font textFont = new Font(FontFamily.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK); Font textFontBold = new Font(FontFamily.HELVETICA, 10, Font.BOLD, BaseColor.BLACK); Font textFontSmall = new Font(FontFamily.HELVETICA, 6, Font.NORMAL, BaseColor.BLACK); PdfPTable table = new PdfPTable(2); float[] rows = { 247.5f, 247.5f }; table.setTotalWidth(rows); table.getDefaultCell().setBorder(Rectangle.BOTTOM); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_JUSTIFIED); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); table.getDefaultCell().setFixedHeight(75); Phrase leftPhrase = new Phrase(); leftPhrase.add(new Chunk( "Hiermit wird die Pflanzung dieser Bäume bescheinigt. Die Pflanzung erfolgt durch die Wald 1.1 gGmbH und kann im Internet unter www.iplantatree.org über die Zertifikat-Nummer #", textFont)); leftPhrase.add(new Chunk(number, textFontBold)); leftPhrase.add(new Chunk(" abgerufen bzw. nachvollzogen werden.", textFont)); Phrase rightPhrase = new Phrase(10f); rightPhrase.add(new Chunk( "Dieses Zertifikat ist keine Bestätigung über Geldzuwendungen im Sinne des § 10 b des Einkommensteuergesetzes an eine der in § 5 Abs. 1 Nr. 9 des Körperschaftsteuergesetzes bezeichneten Körperschaften, Personenvereinigungen oder Vermögensmassen.", textFont)); PdfPCell rightCell = new PdfPCell(); rightCell.setPaddingLeft(10.0f); rightCell.setBorder(Rectangle.BOTTOM); rightCell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); rightCell.setVerticalAlignment(Element.ALIGN_TOP); rightCell.addElement(rightPhrase); PdfPCell dateCell = new PdfPCell(); dateCell.setPaddingTop(10.0f); dateCell.setBorder(Rectangle.NO_BORDER); dateCell.addElement(new Phrase(new Chunk("Datum der Ausstellung: " + date, textFont))); PdfPCell emptyCell = new PdfPCell(); emptyCell.setBorder(Rectangle.NO_BORDER); final Image signatureImage = Image.getInstance(getClass().getResource(_imagePath + "/Unterschrift150.jpg")); PdfPCell underSignatureCell = new PdfPCell(); underSignatureCell.setBorder(Rectangle.NO_BORDER); underSignatureCell.setPadding(0f); Phrase underSignaturePhrase = new Phrase(10f); underSignaturePhrase.add(new Chunk("Unterschrift / Stempel des ausstellenden Unternehmens / der ausstellenden Person", textFontSmall)); underSignatureCell.addElement(underSignaturePhrase); underSignatureCell.setVerticalAlignment(Element.ALIGN_TOP); table.addCell(leftPhrase); table.addCell(rightCell); table.addCell(dateCell); table.addCell(emptyCell); table.addCell(signatureImage); table.addCell(emptyCell); table.addCell(underSignatureCell); table.addCell(emptyCell); table.writeSelectedRows(0, 4, 50, 305, cb); }
private void createTreeCountAndCustomTextBlock(PdfContentByte cb, String customText, int treeCount) throws DocumentException { Font textFont = new Font(FontFamily.TIMES_ROMAN, 16, Font.ITALIC, BaseColor.WHITE); Font textFontTreeCount = new Font(FontFamily.HELVETICA, 30, Font.BOLD, BaseColor.BLACK); Font customTextFont = new Font(FontFamily.HELVETICA, 12, Font.NORMAL, BaseColor.BLACK); cb.saveState(); cb.setRGBColorFill(0x64, 0xA7, 0xBD); cb.rectangle(0.0f, 325.0f, 595.0f, 205.0f); cb.fill(); cb.stroke(); cb.restoreState(); Integer treeCountAsObj = treeCount; PdfPTable table = new PdfPTable(1); float[] rows = { 595f }; table.setTotalWidth(rows); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.getDefaultCell().setFixedHeight(35); table.addCell(new Phrase(new Chunk("über die Pflanzung von", textFont))); table.addCell(new Phrase(new Chunk(treeCountAsObj.toString(), textFontTreeCount))); table.addCell(new Phrase(new Chunk("Bäumen", textFont))); table.writeSelectedRows(0, 3, 0, 520, cb); cb.saveState(); cb.setRGBColorFill(0xF7, 0xF2, 0xF4); cb.rectangle(50.0f, 345.0f, 495.0f, 60.0f); cb.fill(); cb.stroke(); cb.restoreState(); PdfPTable textTable = new PdfPTable(1); float[] textRows = { 475f }; textTable.setTotalWidth(textRows); textTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); textTable.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); textTable.getDefaultCell().setFixedHeight(40); textTable.addCell(new Phrase(new Chunk(customText, customTextFont))); textTable.writeSelectedRows(0, 1, 60, 395, cb); }