List of usage examples for com.lowagie.text Paragraph setSpacingBefore
public void setSpacingBefore(float spacing)
From source file:org.gbif.ipt.task.Eml2Rtf.java
License:Apache License
/** * Add paragraph to Document.// w w w .ja v a 2 s . c o m * * @param doc Document * @param text text of paragraph * @param font Font to be used * @param spacing number of spaces before the paragraph * @param alignType alignment of the paragraph * @throws DocumentException if problem occurs during add */ private void addPara(Document doc, String text, Font font, int spacing, int alignType) throws DocumentException { Paragraph p = new Paragraph(text, font); if (spacing != 0) { p.setSpacingBefore(spacing); } if (alignType != 0) { p.setAlignment(alignType); } doc.add(p); p.clear(); }
From source file:org.goodoldai.jeff.report.pdf.PDFReportBuilder.java
License:Open Source License
/** * This method inserts the header into the PDF report. The header consists * of general data collected from the explanation (date and time created, * owner, title, language and country). If any of this data is missing, it is not * inserted into the report. Since the report format is PDF, the provided * stream should be an instance of com.lowagie.text.Document. * /*from w w w. j a v a 2s . c o m*/ * @param explanation explanation from which the header data is to be * collected * @param stream output stream that the header is supposed to be inserted * into * * @throws org.goodoldai.jeff.explanation.ExplanationException if any of the arguments are * null or if the entered output stream type is not com.lowagie.text.Document */ protected void insertHeader(Explanation explanation, Object stream) { if (explanation == null) { throw new ExplanationException("The argument 'explanation' is mandatory, so it can not be null"); } if (stream == null) { throw new ExplanationException("The argument 'stream' is mandatory, so it can not be null"); } if (!(stream instanceof Document)) { throw new ExplanationException("The entered stream must be a com.lowagie.text.Document instance"); } Document doc = (Document) stream; String owner = explanation.getOwner(); String title = explanation.getTitle(); doc.addCreator("JEFF (Java Explanation Facility Framework)"); doc.addAuthor(owner + " [OWNER]"); doc.addCreationDate(); if (title != null) { try { Phrase p = new Phrase(title, new Font(Font.HELVETICA, 16)); Paragraph pa = new Paragraph(p); pa.setSpacingBefore(10); pa.setSpacingAfter(30); pa.setAlignment(Element.ALIGN_CENTER); doc.add(pa); } catch (DocumentException ex) { throw new ExplanationException(ex.getMessage()); } } }
From source file:org.sakaiproject.evaluation.tool.reporting.EvalPDFReportBuilder.java
License:Educational Community License
public void addTitlePage(String evaltitle, String groupNames, String startDate, String endDate, String responseInformation, byte[] bannerImageBytes, String evalSystemTitle, String informationTitle) { try {// ww w. jav a2s . c om float pagefooter = paragraphFont.getSize(); PdfContentByte cb = pdfWriter.getDirectContent(); float docMiddle = (document.right() - document.left()) / 2 + document.leftMargin(); Paragraph emptyPara = new Paragraph(" "); emptyPara.setSpacingAfter(100.0f); // Title Paragraph titlePara = new Paragraph("\n\n\n" + evaltitle, frontTitleFont); titlePara.setAlignment(Element.ALIGN_CENTER); document.add(titlePara); // Groups Paragraph groupPara = new Paragraph(groupNames, frontAuthorFont); groupPara.setSpacingBefore(25.0f); groupPara.setAlignment(Element.ALIGN_CENTER); document.add(groupPara); // Little info area? I don't know, it was on the mockup though Paragraph infoPara = new Paragraph(informationTitle, frontInfoFont); infoPara.setAlignment(Element.ALIGN_CENTER); infoPara.setSpacingBefore(90.0f); document.add(infoPara); // Started on Paragraph startedPara = new Paragraph(startDate, frontInfoFont); startedPara.setAlignment(Element.ALIGN_CENTER); startedPara.setSpacingBefore(25.0f); document.add(startedPara); // Ended on Paragraph endedPara = new Paragraph(endDate, frontInfoFont); endedPara.setAlignment(Element.ALIGN_CENTER); endedPara.setSpacingBefore(25.0f); document.add(endedPara); // Reply Rate Paragraph replyRatePara = new Paragraph(responseInformation, frontInfoFont); replyRatePara.setAlignment(Element.ALIGN_CENTER); replyRatePara.setSpacingBefore(25.0f); document.add(replyRatePara); // Logo and Tagline cb.beginText(); cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, evalSystemTitle, docMiddle, document.bottom() + 20, 0); cb.endText(); if (bannerImageBytes != null) { Image banner = Image.getInstance(bannerImageBytes); cb.addImage(banner, banner.getWidth(), 0, 0, banner.getHeight(), docMiddle - (banner.getWidth() / 2), document.bottom() + 35); } document.newPage(); responseArea = new ColumnText(cb); responseArea.setSimpleColumn(document.left(), document.top(), document.right() / 2, document.bottom() + pagefooter); responseArea.go(); } catch (DocumentException | IOException de) { throw UniversalRuntimeException.accumulate(de, "Unable to create title page"); } }
From source file:org.sigmah.server.report.renderer.itext.ThemeHelper.java
License:Open Source License
public static Paragraph elementTitle(String title) { Paragraph para = new Paragraph(title); para.setFont(new Font(Font.TIMES_ROMAN, 13, Font.BOLD, new Color(79, 129, 189))); para.setSpacingBefore(10); return para;//from w w w. j a v a 2s .c o m }
From source file:org.tellervo.desktop.print.CompleteBoxLabel.java
License:Open Source License
public void generateBoxLabel(OutputStream output) { try {/* ww w . j a v a 2 s .co m*/ PdfWriter writer = PdfWriter.getInstance(document, output); document.setPageSize(PageSize.LETTER); document.open(); cb = writer.getDirectContent(); // Set basic metadata document.addAuthor("Peter Brewer"); document.addSubject("Box Label"); for (WSIBox b : this.boxlist) { // Title Left ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.top(15) - 210, 368, document.top(15), 20, Element.ALIGN_LEFT); ct.addText(getTitlePDF(b)); ct.go(); // Barcode ColumnText ct2 = new ColumnText(cb); ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20, Element.ALIGN_RIGHT); ct2.addElement(getBarCode(b)); ct2.go(); // Timestamp ColumnText ct3 = new ColumnText(cb); ct3.setSimpleColumn(document.left(), document.top(15) - 223, 350, document.top(15) - 60, 20, Element.ALIGN_LEFT); ct3.setLeading(0, 1.2f); ct3.addText(getTimestampPDF(b)); ct3.go(); // Pad text document.add(new Paragraph(" ")); Paragraph p2 = new Paragraph(); p2.setSpacingBefore(70); p2.setSpacingAfter(10); p2.add(new Chunk(" ", bodyFontLarge)); document.add(new Paragraph(p2)); // Ring samples table addTable(b); document.add(getParagraphSpace()); document.add(getComments(b)); document.newPage(); } } catch (DocumentException de) { System.err.println(de.getMessage()); } // Close the document document.close(); }
From source file:org.tellervo.desktop.print.ProSheet.java
License:Open Source License
private void generateProSheet(OutputStream output) { Paragraph spacingPara = new Paragraph(); spacingPara.setSpacingBefore(10); spacingPara.add(new Chunk(" ", bodyFont)); try {//from ww w .j a va2s. c om PdfWriter writer = PdfWriter.getInstance(document, output); document.setPageSize(PageSize.LETTER); // Set basic metadata document.addAuthor("Peter Brewer"); document.addSubject("Corina Provenience Sheet for " + o.getTitle()); HeaderFooter footer = new HeaderFooter(new Phrase(""), new Phrase("")); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorder(0); document.setFooter(footer); HeaderFooter header = new HeaderFooter(new Phrase(o.getLabCode() + " - " + o.getTitle(), bodyFont), false); header.setAlignment(Element.ALIGN_RIGHT); header.setBorder(0); document.setHeader(header); document.open(); cb = writer.getDirectContent(); // Title Left ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.top() - 193, document.right(), document.top() - 20, 20, Element.ALIGN_LEFT); ct.addText(getTitlePDF()); ct.go(); // Timestamp ColumnText ct3 = new ColumnText(cb); ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20, Element.ALIGN_LEFT); ct3.setLeading(0, 1.2f); ct3.addText(getTimestampPDF()); ct3.go(); // Pad text document.add(spacingPara); document.add(getObjectDescription()); document.add(getObjectComments()); document.add(spacingPara); getElementTable(); } catch (DocumentException de) { System.err.println(de.getMessage()); } // Close the document document.close(); }
From source file:org.tellervo.desktop.print.ProSheet.java
License:Open Source License
private Paragraph getObjectDescription() { Paragraph p = new Paragraph(); p.setLeading(0, 1.2f);// w w w .ja v a 2 s. co m p.setAlignment(Element.ALIGN_JUSTIFIED); p.setSpacingAfter(10); p.setSpacingBefore(50); if (o.getDescription() != null) { p.add(new Chunk(o.getDescription(), bodyFont)); } else { p.add(new Chunk("No description recorded", bodyFont)); } return p; }
From source file:org.tellervo.desktop.print.SeriesReport.java
License:Open Source License
private void generateSeriesReport(OutputStream output) { displayUnits = NormalTridasUnit// w w w .j av a2 s .co m .valueOf(App.prefs.getPref(PrefKey.DISPLAY_UNITS, NormalTridasUnit.MICROMETRES.name().toString())); try { PdfWriter writer = PdfWriter.getInstance(document, output); document.setPageSize(PageSize.LETTER); document.open(); cb = writer.getDirectContent(); // Set basic metadata document.addAuthor("Peter Brewer"); document.addSubject("Tellervo Series Report for " + s.getDisplayTitle()); // Title Left ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.top() - 163, 283, document.top(), 20, Element.ALIGN_LEFT); ct.addText(getTitlePDF()); ct.go(); // Barcode ColumnText ct2 = new ColumnText(cb); ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20, Element.ALIGN_RIGHT); ct2.addElement(getBarCode()); ct2.go(); // Timestamp ColumnText ct3 = new ColumnText(cb); ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20, Element.ALIGN_LEFT); ct3.setLeading(0, 1.2f); ct3.addText(getTimestampPDF()); ct3.go(); // Authorship ColumnText ct4 = new ColumnText(cb); ct4.setSimpleColumn(284, document.top() - 223, document.right(10), document.top() - 60, 20, Element.ALIGN_RIGHT); ct4.setLeading(0, 1.2f); ct4.addText(getAuthorshipPDF()); ct4.go(); // Pad text document.add(new Paragraph(" ")); Paragraph p2 = new Paragraph(); p2.setSpacingBefore(50); p2.setSpacingAfter(10); p2.add(new Chunk(" ", bodyFont)); document.add(new Paragraph(p2)); // Ring width table getRingWidthTable(); document.add(getParagraphSpace()); if (s.getSeries() instanceof TridasMeasurementSeries) { // MEASUREMENT SERIES //document.add(getRingRemarks()); document.add(getWoodCompletenessPDF()); document.add(getParagraphSpace()); document.add(getSeriesComments()); document.add(getParagraphSpace()); document.add(getInterpretationPDF()); document.add(getParagraphSpace()); document.add(getElementAndSampleInfo()); } else { // DERIVED SERIES getWJTable(); document.add(getParagraphSpace()); document.add(getSeriesComments()); document.add(getParagraphSpace()); //document.add(getRingRemarks()); } } catch (DocumentException de) { System.err.println(de.getMessage()); } // Close the document document.close(); }
From source file:oscar.form.pdfservlet.FrmCustomedPDFServlet.java
License:Open Source License
protected ByteArrayOutputStream generatePDFDocumentBytes(final HttpServletRequest req, final ServletContext ctx) throws DocumentException { logger.debug("***in generatePDFDocumentBytes2 FrmCustomedPDFServlet.java***"); // added by vic, hsfo Enumeration<String> em = req.getParameterNames(); while (em.hasMoreElements()) { logger.debug("para=" + em.nextElement()); }/* ww w. j a va2 s . c o m*/ em = req.getAttributeNames(); while (em.hasMoreElements()) logger.debug("attr: " + em.nextElement()); if (HSFO_RX_DATA_KEY.equals(req.getParameter("__title"))) { return generateHsfoRxPDF(req); } String newline = System.getProperty("line.separator"); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter writer = null; String method = req.getParameter("__method"); String origPrintDate = null; String numPrint = null; if (method != null && method.equalsIgnoreCase("rePrint")) { origPrintDate = req.getParameter("origPrintDate"); numPrint = req.getParameter("numPrints"); } logger.debug("method in generatePDFDocumentBytes " + method); String clinicName; String clinicTel; String clinicFax; // check if satellite clinic is used String useSatelliteClinic = req.getParameter("useSC"); logger.debug(useSatelliteClinic); if (useSatelliteClinic != null && useSatelliteClinic.equalsIgnoreCase("true")) { String scAddress = req.getParameter("scAddress"); logger.debug("clinic detail" + "=" + scAddress); HashMap<String, String> hm = parseSCAddress(scAddress); clinicName = hm.get("clinicName"); clinicTel = hm.get("clinicTel"); clinicFax = hm.get("clinicFax"); } else { // parameters need to be passed to header and footer clinicName = req.getParameter("clinicName"); logger.debug("clinicName" + "=" + clinicName); clinicTel = req.getParameter("clinicPhone"); clinicFax = req.getParameter("clinicFax"); } String patientPhone = req.getParameter("patientPhone"); String patientCityPostal = req.getParameter("patientCityPostal"); String patientAddress = req.getParameter("patientAddress"); String patientName = req.getParameter("patientName"); String sigDoctorName = req.getParameter("sigDoctorName"); String rxDate = req.getParameter("rxDate"); String rx = req.getParameter("rx"); String patientDOB = req.getParameter("patientDOB"); String showPatientDOB = req.getParameter("showPatientDOB"); String imgFile = req.getParameter("imgFile"); String patientHIN = req.getParameter("patientHIN"); String patientChartNo = req.getParameter("patientChartNo"); String pracNo = req.getParameter("pracNo"); Locale locale = req.getLocale(); boolean isShowDemoDOB = false; if (showPatientDOB != null && showPatientDOB.equalsIgnoreCase("true")) { isShowDemoDOB = true; } if (!isShowDemoDOB) patientDOB = ""; if (rx == null) { rx = ""; } String additNotes = req.getParameter("additNotes"); String[] rxA = rx.split(newline); List<String> listRx = new ArrayList<String>(); String listElem = ""; // parse rx and put into a list of rx; for (String s : rxA) { if (s.equals("") || s.equals(newline) || s.length() == 1) { listRx.add(listElem); listElem = ""; } else { listElem = listElem + s; listElem += newline; } } // get the print prop values Properties props = new Properties(); StringBuilder temp = new StringBuilder(); for (Enumeration<String> e = req.getParameterNames(); e.hasMoreElements();) { temp = new StringBuilder(e.nextElement().toString()); props.setProperty(temp.toString(), req.getParameter(temp.toString())); } for (Enumeration<String> e = req.getAttributeNames(); e.hasMoreElements();) { temp = new StringBuilder(e.nextElement().toString()); props.setProperty(temp.toString(), req.getAttribute(temp.toString()).toString()); } Document document = new Document(); try { String title = req.getParameter("__title") != null ? req.getParameter("__title") : "Unknown"; // specify the page of the picture using __graphicPage, it may be used multiple times to specify multiple pages // however the same graphic will be applied to all pages // ie. __graphicPage=2&__graphicPage=3 String[] cfgGraphicFile = req.getParameterValues("__cfgGraphicFile"); int cfgGraphicFileNo = cfgGraphicFile == null ? 0 : cfgGraphicFile.length; if (cfgGraphicFile != null) { // for (String s : cfgGraphicFile) { // p("cfgGraphicFile", s); // } } String[] graphicPage = req.getParameterValues("__graphicPage"); ArrayList<String> graphicPageArray = new ArrayList<String>(); if (graphicPage != null) { // for (String s : graphicPage) { // p("graphicPage", s); // } graphicPageArray = new ArrayList<String>(Arrays.asList(graphicPage)); } // A0-A10, LEGAL, LETTER, HALFLETTER, _11x17, LEDGER, NOTE, B0-B5, ARCH_A-ARCH_E, FLSA // and FLSE // the following shows a temp way to get a print page size Rectangle pageSize = PageSize.LETTER; String pageSizeParameter = req.getParameter("rxPageSize"); if (pageSizeParameter != null) { if ("PageSize.HALFLETTER".equals(pageSizeParameter)) { pageSize = PageSize.HALFLETTER; } else if ("PageSize.A6".equals(pageSizeParameter)) { pageSize = PageSize.A6; } else if ("PageSize.A4".equals(pageSizeParameter)) { pageSize = PageSize.A4; } } /* * if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.HALFLETTER; } else if ("PageSize.A6".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.A6; } else if * ("PageSize.A4".equals(props.getProperty(PAGESIZE))) { pageSize = PageSize.A4; } */ // p("size of page ", props.getProperty(PAGESIZE)); document.setPageSize(pageSize); // 285=left margin+width of box, 5f is space for looking nice document.setMargins(15, pageSize.getWidth() - 285f + 5f, 170, 60);// left, right, top , bottom writer = PdfWriter.getInstance(document, baosPDF); writer.setPageEvent(new EndPage(clinicName, clinicTel, clinicFax, patientPhone, patientCityPostal, patientAddress, patientName, patientDOB, sigDoctorName, rxDate, origPrintDate, numPrint, imgFile, patientHIN, patientChartNo, pracNo, locale)); document.addTitle(title); document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); document.open(); document.newPage(); PdfContentByte cb = writer.getDirectContent(); BaseFont bf; // = normFont; cb.setRGBColorStroke(0, 0, 255); // render prescriptions for (String rxStr : listRx) { bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph(new Phrase(rxStr, new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(5f); document.add(p); } // render additional notes if (additNotes != null && !additNotes.equals("")) { bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph(new Phrase(additNotes, new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(10f); document.add(p); } // render optometristEyeParam if (req.getAttribute("optometristEyeParam") != null) { bf = BaseFont.createFont(BaseFont.COURIER, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Paragraph p = new Paragraph( new Phrase("Eye " + (String) req.getAttribute("optometristEyeParam"), new Font(bf, 10))); p.setKeepTogether(true); p.setSpacingBefore(15f); document.add(p); } // render QrCode if (PrescriptionQrCodeUIBean.isPrescriptionQrCodeEnabledForCurrentProvider()) { Integer scriptId = Integer.parseInt(req.getParameter("scriptId")); byte[] qrCodeImage = PrescriptionQrCodeUIBean.getPrescriptionHl7QrCodeImage(scriptId); Image qrCode = Image.getInstance(qrCodeImage); document.add(qrCode); } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } catch (Exception e) { logger.error("Error", e); } finally { if (document != null) { document.close(); } if (writer != null) { writer.close(); } } logger.debug("***END in generatePDFDocumentBytes2 FrmCustomedPDFServlet.java***"); return baosPDF; }
From source file:pl.exsio.ca.app.report.terraincard.view.TerrainCardsView.java
License:Open Source License
private Cell getColumnTitleCell(String title) throws Exception { Paragraph p = new Paragraph(title, this.getFont()); p.getFont().setSize(10);/*from ww w .j ava 2 s. c o m*/ p.getFont().setStyle(Font.BOLDITALIC); p.setSpacingAfter(2); p.setSpacingBefore(2); Cell cell = new Cell(p); cell.setColspan(2); cell.setBackgroundColor(new Color(230, 230, 230)); return cell; }