List of usage examples for com.lowagie.text.pdf.draw LineSeparator LineSeparator
public LineSeparator(float lineWidth, float percentage, Color lineColor, int align, float offset)
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
@Override public void addDocumentHeader(final Document document, final String name, final String documenTitle, final String documentAuthor, final Date date) throws DocumentException { SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale()); LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0); document.add(Chunk.NEWLINE);/*from ww w . ja v a 2 s .c o m*/ Paragraph title = new Paragraph(new Phrase(documenTitle, FontUtils.getDejavuBold17Light())); title.add(new Phrase(" " + name, FontUtils.getDejavuBold17Dark())); title.setSpacingAfter(7f); document.add(title); document.add(line); PdfPTable userAndDate = new PdfPTable(2); userAndDate.setWidthPercentage(100f); userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT); userAndDate.getDefaultCell().setBorderWidth(0); Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light())); userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark())); Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light()); userAndDate.addCell(userParagraph); userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); userAndDate.addCell(dateParagraph); userAndDate.setSpacingAfter(14f); document.add(userAndDate); }
From source file:com.qcadoo.report.internal.PdfHelperImpl.java
License:Open Source License
@Override public void addDocumentHeaderThin(final Document document, final String name, final String documentTitle, final String documentAuthor, final Date date) throws DocumentException { SimpleDateFormat df = new SimpleDateFormat(DateUtils.L_DATE_TIME_FORMAT, getLocale()); LineSeparator line = new LineSeparator(2, 100f, ColorUtils.getLineDarkColor(), Element.ALIGN_LEFT, 0); Paragraph title = new Paragraph(new Phrase(documentTitle, FontUtils.getDejavuBold14Light())); title.add(new Phrase(" " + name, FontUtils.getDejavuBold14Dark())); title.setSpacingAfter(7f);/* w ww. j ava2s . c o m*/ document.add(title); document.add(line); PdfPTable userAndDate = new PdfPTable(2); userAndDate.setWidthPercentage(100f); userAndDate.setHorizontalAlignment(Element.ALIGN_LEFT); userAndDate.getDefaultCell().setBorderWidth(0); Paragraph userParagraph = new Paragraph(new Phrase(documentAuthor, FontUtils.getDejavuRegular9Light())); userParagraph.add(new Phrase(" " + getDocumentAuthor(), FontUtils.getDejavuRegular9Dark())); Paragraph dateParagraph = new Paragraph(df.format(date), FontUtils.getDejavuRegular9Light()); userAndDate.addCell(userParagraph); userAndDate.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); userAndDate.addCell(dateParagraph); userAndDate.setSpacingAfter(10f); document.add(userAndDate); }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.CaseStudieSummaryPDF.java
License:Open Source License
/** * Entering the project title in the summary *///w w w.j a v a 2s.c om private void addProjectTitle() { LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -7); Paragraph paragraph = new Paragraph(); line.setLineColor(titleColor); try { paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.setFont(BODY_TEXT_BOLD_FONT); paragraph.add("Project: "); paragraph.setFont(BODY_TEXT_FONT); paragraph.add(this.messageReturn("P" + project.getId() + " - ")); paragraph.add(this.messageReturn(project.getTitle())); paragraph.add(line); document.add(paragraph); document.add(Chunk.NEWLINE); ; } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } }
From source file:org.cgiar.ccafs.ap.summaries.projects.pdf.ProjectSummaryPDF.java
License:Open Source License
/** * Entering the project title in the summary *//* w ww . j a v a2 s . c om*/ private void addProjectTitle() { LineSeparator line = new LineSeparator(1, 100, null, Element.ALIGN_CENTER, -7); Paragraph paragraph = new Paragraph(); line.setLineColor(titleColor); try { paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.setFont(BODY_TEXT_BOLD_FONT); paragraph.add("Title: "); paragraph.setFont(BODY_TEXT_FONT); paragraph.add(this.messageReturn(project.getTitle())); paragraph.add(line); document.add(paragraph); document.add(Chunk.NEWLINE); ; } catch (DocumentException e) { LOG.error("There was an error trying to add the project title to the project summary pdf", e); } }
From source file:questions.separators.LineSeparator1.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w . j ava2 s.c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph separator = new Paragraph(0); separator.add(new Chunk(new LineSeparator(1, 80, Color.RED, Element.ALIGN_LEFT, -2))); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(StarSeparators.TEXT); column.addElement(separator); } column.setSimpleColumn(36, 36, 295, 806); column.go(); column.setSimpleColumn(300, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 10; i++) { document.add(StarSeparators.TEXT); document.add(separator); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.LineSeparator2.java
public static void main(String[] args) { Document document = new Document(); try {/*from w ww. ja v a2s.c o m*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); VerticalPositionMark separator = new LineSeparator(1, 80, Color.RED, Element.ALIGN_RIGHT, -2); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(StarSeparators.TEXT); column.addElement(separator); } column.setSimpleColumn(36, 36, 295, 806); column.go(); column.setSimpleColumn(300, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 10; i++) { document.add(StarSeparators.TEXT); document.add(separator); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.LineSeparator3.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w. j a v a 2 s. c om*/ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Paragraph p = new Paragraph(StarSeparators.TEXT); VerticalPositionMark separator = new LineSeparator(1, 100, Color.RED, Element.ALIGN_RIGHT, -2); p.add(separator); ColumnText column = new ColumnText(writer.getDirectContent()); for (int i = 0; i < 5; i++) { column.addElement(p); } column.setSimpleColumn(36, 36, 295, 806); column.go(); column.setSimpleColumn(300, 36, 559, 806); column.go(); document.newPage(); for (int i = 0; i < 10; i++) { document.add(p); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:questions.separators.SeparatedWords2.java
public static void main(String[] args) { Document document = new Document(); try {/*from ww w . j a v a 2s . c o m*/ PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); Phrase p; Chunk separator = new Chunk(new LineSeparator(0.5f, 70, Color.RED, Element.ALIGN_CENTER, 3)); for (int i = 0; i < 40; i++) { p = new Phrase("TEST"); p.add(separator); p.add(new Chunk(String.valueOf(i))); p.add(separator); p.add(new Chunk(String.valueOf(i * 2))); p.add(separator); p.add(new Chunk(WORDS[39 - i])); p.add(separator); p.add(new Chunk(String.valueOf(i * 4))); p.add(separator); p.add(new Chunk(WORDS[i])); document.add(p); document.add(Chunk.NEWLINE); } document.close(); } catch (Exception de) { de.printStackTrace(); } }
From source file:za.co.equalpay.web.utils.PDFExportUtility.java
/** * Perform the standard PDF PreProcessing: <br> * Add Customer logo image and Phrase as header to the first page, <br> * Add Line Separator to the bottom of the Image <br> * and add the standard footer message to the PDF document<br> * * @throws MalformedURLException/*from w ww.j ava2 s. com*/ * @throws IOException * @throws DocumentException */ public void preProcess() throws MalformedURLException, IOException, DocumentException { document.setMargins(50f, 50f, 10f, 20f); BaseFont bf_helv = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); // Font font = new Font(bf_helv, 8); ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext() .getContext(); String fontPath = LogoPathFinder.getFontPath(servletContext, "Tahoma"); BaseFont bf = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H, true); Font tahoma = new Font(bf, 16, Font.BOLD); tahoma.setColor(Color.GRAY); Font fontBold = new Font(bf, 8, Font.BOLD); fontBold.setColor(Color.GRAY); Font f = new Font(bf, 8, Font.NORMAL); f.setColor(Color.GRAY); Font sf = new Font(bf, 6, Font.NORMAL); sf.setColor(Color.LIGHT_GRAY); // image.setIndentationLeft(360f); // PdfPCell imgCell = new PdfPCell(image, false); // imgCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); // imgCell.setBorder(0); // // PdfPCell emptyCell = new PdfPCell(new Phrase("TESTING...", tahoma)); // emptyCell.setBorder(0); // PdfPTable footerTable = new PdfPTable(1); // footerTable.setWidthPercentage(100); // // // phrase = new Phrase(PDF_FOOTER_MESSAGE, f); // // PdfPCell cell = new PdfPCell(phrase); // cell.setBorder(0); // footerTable.addCell(cell); // table.setWidths(new int[] { 1, 2 }); // table.addCell(emptyCell); // footerTable.addCell(emptyCell); // phrase.add(footerTable); // phrase.add(new Chunk(image, 475f, 0)); // Phrase subPhrase = new Phrase(); // subPhrase.add(new Phrase("\nwww.meddev.co.za\n", sf)); // subPhrase.add(new Phrase(PDF_FOOTER_MESSAGE, f)); // phrase.add(subPhrase); // phrase.add(new Chunk("www.meddev.co.za", f)); // phrase.add(new Phrase(PDF_FOOTER_MESSAGE, f)); // load document footer HeaderFooter footer = new HeaderFooter(new Phrase(PDF_FOOTER_MESSAGE, f), false); // HeaderFooter footer = new HeaderFooter(paragraph, false); // HeaderFooter footer = new HeaderFooter(phrase, false); footer.setAlignment(Element.ALIGN_LEFT); footer.setBorder(Rectangle.NO_BORDER); document.setFooter(footer); // document.open(); // // ByteArrayOutputStream baos = new ByteArrayOutputStream(); // PdfWriter writer = PdfWriter.getInstance(document, baos); // // writer.open(); // PdfContentByte cb = writer.getDirectContent(); // cb.addImage(image); // ColumnText columnText = new ColumnText(cb); // load the customer logo String logoPath = LogoPathFinder.getPath(servletContext, "meddev-logo2"); Image image = Image.getInstance(logoPath); image.scaleToFit(149, 55); image.setIndentationLeft(360f); PdfPCell imageCell = new PdfPCell(image, false); imageCell.setHorizontalAlignment(PdfPCell.ALIGN_RIGHT); imageCell.setBorder(0); PdfPCell headerTextCell = new PdfPCell(new Phrase(header, tahoma)); headerTextCell.setBorder(0); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.setWidths(new int[] { 1, 2 }); table.addCell(headerTextCell); table.addCell(imageCell); phrase = new Phrase(); phrase.add(table); // load document header HeaderFooter header = new HeaderFooter(phrase, false); header.setAlignment(Element.ALIGN_CENTER); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); // create gray line separator // Chunk lineSeparator = new Chunk(new LineSeparator(1, 100, Color.GRAY, // Element.ALIGN_CENTER, -2)); // document.add(lineSeparator); Font headerFont = new Font(bf_helv, 9); // write the header lines for this statement phrase = new Phrase(12, "\n", headerFont); phrase.add("\n\n"); // open the pdf document for editing document.open(); document.setPageSize(PageSize.A4); // Meddev Information Block table = new PdfPTable(4); table.setWidthPercentage(100); // table.setWidths(new int[] { 25, 25, 30, 20 }); Phrase phrase1 = new Phrase(); phrase1.add(new Phrase("MED DEV cc", fontBold)); phrase1.add(new Phrase("\nUNIT 10, THE CORNER", f)); phrase1.add(new Phrase("\nc/o Theuns & Hilde Ave", f)); phrase1.add(new Phrase("\nHennopspark, 0157", f)); phrase1.add(new Phrase("\nTel: +27 (0) 12 653 3063", f)); phrase1.add(new Phrase("\nReg No: 2006/166603/23", f)); phrase1.add(new Phrase("\n", f)); Phrase phrase2 = new Phrase(); phrase2.add(new Phrase("VAT No: ", fontBold)); phrase2.add(new Phrase("4150231498", f)); phrase2.add(new Phrase("\nImport/Export #: ", fontBold)); phrase2.add(new Phrase("20544748", f)); phrase2.add(new Phrase("\n", f)); Phrase phrase3 = new Phrase(); phrase3.add(new Phrase("QUOTE NO ", fontBold)); phrase3.add(new Phrase("\nDATE ", fontBold)); phrase3.add(new Phrase("\nREFERNCE ", fontBold)); phrase3.add(new Phrase("\nSUPPLIER CODE ", fontBold)); phrase3.add(new Phrase("\nEXPIRY DATE ", fontBold)); Phrase phrase4 = new Phrase(); // phrase4.add(new Phrase(quotation.getQuotationNumber(), f)); // phrase4.add(new Phrase("\n" + DateFormatter.formatMonthDate(quotation.getQuotationDate()), f)); // phrase4.add(new Phrase("\n" + (quotation.getClient().getReference() == null ? "-" : quotation.getClient().getReference()), f)); // phrase4.add(new Phrase("\nMEDDEV1", f)); // phrase4.add(new Phrase("\n" + DateFormatter.formatMonthDate(quotation.calculateExpiryDate()), f)); PdfPCell cell1 = new PdfPCell(phrase1); cell1.setBorder(0); PdfPCell cell2 = new PdfPCell(phrase2); cell2.setBorder(0); PdfPCell cell3 = new PdfPCell(phrase3); cell3.setBorder(0); PdfPCell cell4 = new PdfPCell(phrase4); cell4.setBorder(0); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); table.addCell(cell4); phrase.add(table); // create gray line separator Chunk lineSeparator = new Chunk(new LineSeparator(1, 100, Color.GRAY, Element.ALIGN_CENTER, -2)); phrase.add(lineSeparator); // Customer Information Block table = new PdfPTable(3); table.setWidthPercentage(100); table.setWidths(new int[] { 5, 2, 3 }); // Phrase phrase11 = new Phrase(); // phrase11.add(new Phrase(quotation.getClient().getCompany().toUpperCase() + "(CLIENT)", fontBold)); // if (quotation.getClient().getVatRegNo() != null && quotation.getClient().getVatRegNo().trim().length() > 0) { // phrase11.add(new Phrase("\nCustomer VAT No: ", fontBold)); // phrase11.add(new Phrase(quotation.getClient().getVatRegNo(), f)); // } // if (quotation.getClient().getResAddress1() != null && quotation.getClient().getResAddress1().trim().length() > 0) { // phrase11.add(new Phrase("\n" + quotation.getClient().getResAddress1(), f)); // } // if (quotation.getClient().getResAddress2() != null && quotation.getClient().getResAddress2().trim().length() > 0) { // phrase11.add(new Phrase("\n" + quotation.getClient().getResAddress2(), f)); // } // if (quotation.getClient().getResCity() != null && quotation.getClient().getResCity().trim().length() > 0) { // phrase11.add(new Phrase("\n" + quotation.getClient().getResCity(), f)); // } // if (quotation.getClient().getPhone() != null && quotation.getClient().getPhone().trim().length() > 0) { // phrase11.add(new Phrase("\nTel: " + quotation.getClient().getPhone(), f)); // } //PdfPCell cell11 = new PdfPCell(phrase11); //cell11.setBorder(0); phrase2 = new Phrase(); phrase2.add(new Phrase("CURRENCY: ", fontBold)); PdfPCell cell12 = new PdfPCell(phrase2); cell12.setBorder(0); phrase3 = new Phrase(); //phrase3.add(new Phrase(quotation.getClient().getCurrencyCode(), f)); PdfPCell cell13 = new PdfPCell(phrase3); cell13.setBorder(0); // table.addCell(cell11); table.addCell(cell12); table.addCell(cell13); phrase.add(table); // create gray line separator phrase.add("\n"); document.add(phrase); String footerImagePath = LogoPathFinder.getPath(servletContext, "footer-image"); Image footerImage = Image.getInstance(footerImagePath); footerImage.scaleToFit(90, 50); footerImage.setAbsolutePosition((PageSize.A4.getWidth() - (footerImage.getScaledWidth() + 40)), (PageSize.A4.getHeight() - (PageSize.A4.getHeight() - (footerImage.getScaledHeight() - 10)))); document.add(footerImage); }