List of usage examples for com.lowagie.text Document right
public float right()
From source file:jm.web.Addons.java
License:GNU General Public License
public static void setPie(PdfWriter writer, Document document, String rep_pie) { try {/*from w w w.j a v a 2s .com*/ PdfContentByte cb = writer.getDirectContent(); /*cb.setLineWidth(2); cb.moveTo(60, document.bottomMargin()-5); cb.lineTo(document.right() - document.left()-70, document.bottomMargin()-5); */ PdfPTable pie = new PdfPTable(1); pie.setTotalWidth(document.right() - document.left() - 120); pie.addCell(Addons.setCeldaPDF(rep_pie, Font.HELVETICA, 9, Font.BOLD, Element.ALIGN_CENTER, 0)); pie.addCell(Addons.setCeldaPDF("Pg " + String.valueOf(writer.getPageNumber()), Font.HELVETICA, 9, Font.BOLD, Element.ALIGN_RIGHT, 0)); pie.addCell(Addons.setCeldaPDF( "Reporte diseado por: Jorge Mueses Cevallos. Mvil: 095204832 mail:jorge_mueses@yahoo.com", Font.HELVETICA, 5, Font.BOLD, Element.ALIGN_LEFT, 0)); pie.writeSelectedRows(0, -1, 60, document.bottomMargin() - 10, cb); } catch (Exception e) { throw new ExceptionConverter(e); } }
From source file:mitm.common.pdf.MessagePDFBuilder.java
License:Open Source License
public void buildPDF(MimeMessage message, String replyURL, OutputStream pdfStream) throws DocumentException, MessagingException, IOException { Document document = createDocument(); PdfWriter pdfWriter = createPdfWriter(document, pdfStream); document.open();/*from www . j a va 2 s . co m*/ String[] froms = null; try { froms = EmailAddressUtils.addressesToStrings(message.getFrom(), true /* mime decode */); } catch (MessagingException e) { logger.warn("From address is not a valid email address."); } if (froms != null) { for (String from : froms) { document.addAuthor(from); } } String subject = null; try { subject = message.getSubject(); } catch (MessagingException e) { logger.error("Error getting subject.", e); } if (subject != null) { document.addSubject(subject); document.addTitle(subject); } String[] tos = null; try { tos = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.TO), true /* mime decode */); } catch (MessagingException e) { logger.warn("To is not a valid email address."); } String[] ccs = null; try { ccs = EmailAddressUtils.addressesToStrings(message.getRecipients(RecipientType.CC), true /* mime decode */); } catch (MessagingException e) { logger.warn("CC is not a valid email address."); } Date sentDate = null; try { sentDate = message.getSentDate(); } catch (MessagingException e) { logger.error("Error getting sent date.", e); } Collection<Part> attachments = new LinkedList<Part>(); String body = BodyPartUtils.getPlainBodyAndAttachments(message, attachments); attachments = preprocessAttachments(attachments); if (body == null) { body = MISSING_BODY; } /* * PDF does not have tab support so we convert tabs to spaces */ body = StringReplaceUtils.replaceTabsWithSpaces(body, tabWidth); PdfPTable headerTable = new PdfPTable(2); headerTable.setHorizontalAlignment(Element.ALIGN_LEFT); headerTable.setWidthPercentage(100); headerTable.setWidths(new int[] { 1, 6 }); headerTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); Font headerFont = createHeaderFont(); FontSelector headerFontSelector = createHeaderFontSelector(); PdfPCell cell = new PdfPCell(new Paragraph("From:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); String decodedFroms = StringUtils.defaultString(StringUtils.join(froms, ", ")); headerTable.addCell(headerFontSelector.process(decodedFroms)); cell = new PdfPCell(new Paragraph("To:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(tos, ", ")))); cell = new PdfPCell(new Paragraph("CC:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(StringUtils.join(ccs, ", ")))); cell = new PdfPCell(new Paragraph("Subject:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(headerFontSelector.process(StringUtils.defaultString(subject))); cell = new PdfPCell(new Paragraph("Date:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable.addCell(ObjectUtils.toString(sentDate)); cell = new PdfPCell(new Paragraph("Attachments:", headerFont)); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); headerTable.addCell(cell); headerTable .addCell(headerFontSelector.process(StringUtils.defaultString(getAttachmentHeader(attachments)))); document.add(headerTable); if (replyURL != null) { addReplyLink(document, replyURL); } /* * Body table will contain the body of the message */ PdfPTable bodyTable = new PdfPTable(1); bodyTable.setWidthPercentage(100f); bodyTable.setSplitLate(false); bodyTable.setSpacingBefore(15f); bodyTable.setHorizontalAlignment(Element.ALIGN_LEFT); addBodyAndAttachments(pdfWriter, document, bodyTable, body, attachments); Phrase footer = new Phrase(FOOTER_TEXT); PdfContentByte cb = pdfWriter.getDirectContent(); ColumnText.showTextAligned(cb, Element.ALIGN_RIGHT, footer, document.right(), document.bottom(), 0); document.close(); }
From source file:nl.knaw.dans.common.lang.pdf.PdfPageLayouter.java
License:Apache License
private float getCenterX(final Document document) { return (document.right() - document.left()) / 2 + document.leftMargin(); }
From source file:org.kuali.kfs.module.purap.pdf.PurapPdf.java
License:Open Source License
/** * Overrides the method in PdfPageEventHelper from itext to write the headerTable, compose the footer and show the * footer./*from w ww. ja v a 2s. c o m*/ * * @param writer The PdfWriter for this document. * @param document The document. * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ @Override public void onEndPage(PdfWriter writer, Document document) { LOG.debug("onEndPage() started."); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); // write the headerTable headerTable.setTotalWidth(document.right() - document.left()); headerTable.writeSelectedRows(0, -1, document.left(), document.getPageSize().height() - 10, cb); // compose the footer String text = "Page " + writer.getPageNumber() + " of "; float textSize = helv.getWidthPoint(text, 12); float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(helv, 12); // show the footer float adjust = helv.getWidthPoint("0", 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(tpl, document.right() - adjust, textBase); cb.saveState(); }
From source file:org.kuali.kfs.module.purap.pdf.PurchaseOrderQuoteRequestsPdf.java
License:Open Source License
/** * Overrides the method in PdfPageEventHelper from itext to compose the footer and show the * footer./*from w w w .j a va 2s . co m*/ * * @param writer The PdfWriter for this document. * @param document The document. * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { LOG.debug("onEndPage() started."); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); // compose the footer String text = "Page " + writer.getPageNumber() + " of "; float textSize = helv.getWidthPoint(text, 12); float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(helv, 12); // show the footer float adjust = helv.getWidthPoint("0", 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(tpl, document.right() - adjust, textBase); cb.saveState(); }
From source file:org.kuali.ole.module.purap.pdf.PurapPdf.java
License:Educational Community License
/** * Overrides the method in PdfPageEventHelper from itext to write the headerTable, compose the footer and show the * footer./*from w w w .j a v a2s . c o m*/ * * @param writer The PdfWriter for this document. * @param document The document. * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ public void onEndPage(PdfWriter writer, Document document) { LOG.debug("onEndPage() started."); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); // write the headerTable headerTable.setTotalWidth(document.right() - document.left()); headerTable.writeSelectedRows(0, -1, document.left(), document.getPageSize().height() - 10, cb); // compose the footer String text = "Page " + writer.getPageNumber() + " of "; float textSize = helv.getWidthPoint(text, 12); float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(helv, 12); // show the footer float adjust = helv.getWidthPoint("0", 12); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(tpl, document.right() - adjust, textBase); cb.saveState(); }
From source file:org.mapfish.print.PDFCustomBlocks.java
License:Open Source License
private void addHeader(Document document, PdfContentByte dc) { if (header != null) { Rectangle rectangle = new Rectangle(document.left(), document.top(), document.right(), document.top() + header.getHeight()); header.render(rectangle, dc, headerParams, context); }/*from ww w . j a v a 2s.co m*/ }
From source file:org.mapfish.print.PDFCustomBlocks.java
License:Open Source License
private void addFooter(Document document, PdfContentByte dc) { if (footer != null) { Rectangle rectangle = new Rectangle(document.left(), document.bottom() - footer.getHeight(), document.right(), document.bottom()); footer.render(rectangle, dc, footerParams, context); }//ww w .ja v a2s . c o m }
From source file:org.opentestsystem.delivery.testreg.rest.view.PdfReportPageEventHelper.java
License:Open Source License
@Override public void onEndPage(final PdfWriter writer, final Document document) { PdfContentByte cb = writer.getDirectContent(); if (document.getPageNumber() == 1) { ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(""), (document.right() - document.left()) / 2 + document.leftMargin(), document.top() - 5, 0f); }/* w w w.ja v a 2s . c o m*/ ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, new Phrase(""), document.left(), document.bottom() - 15, 0f); int pageN = writer.getPageNumber(); String text = "Page " + pageN + " of "; cb.beginText(); cb.setFontAndSize(helv, 11); cb.setTextMatrix(document.right() - document.rightMargin() - 10, document.bottom() - 15); cb.showText(text); cb.endText(); cb.addTemplate(template, document.right(), document.bottom() - 15); }
From source file:org.posterita.core.PDFReportPageEventHelper.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { PdfContentByte cb = writer.getDirectContent(); cb.saveState();//from w w w . j av a2 s . com // write the headertable table.setTotalWidth(document.right() - document.left()); table.writeSelectedRows(0, -1, document.left(), document.getPageSize().getHeight() - 50, cb); // compose the footer String text = "Page " + writer.getPageNumber() + " of "; float textSize = PAGE_FOOTER_FONT.getBaseFont().getWidthPoint(text, 10); float textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(PAGE_FOOTER_FONT.getBaseFont(), 10); float adjust = PAGE_FOOTER_FONT.getBaseFont().getWidthPoint("0", 10); cb.setTextMatrix(document.right() - textSize - adjust, textBase); cb.showText(text); cb.endText(); cb.addTemplate(tpl, document.right() - adjust, textBase); cb.saveState(); text = "Report Generated on : " + dateAndTime; textSize = PAGE_FOOTER_FONT.getBaseFont().getWidthPoint(text, 10); textBase = document.bottom() - 20; cb.beginText(); cb.setFontAndSize(PAGE_FOOTER_FONT.getBaseFont(), 10); adjust = PAGE_FOOTER_FONT.getBaseFont().getWidthPoint("0", 10); cb.setTextMatrix(MARGIN, textBase); cb.showText(text); cb.endText(); cb.saveState(); }