List of usage examples for com.lowagie.text Document addSubject
public boolean addSubject(String subject)
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()); }/*from w w w. j a v a 2 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:peakml.graphics.JFreeChartTools.java
License:Open Source License
/** * This method writes the given graph to the output stream in the PDF format. As a vector * based file format it allows some freedom to be changed (e.g. colors, line thickness, etc.), * which can be convenient for presentation purposes. * //from w w w .j a va2s . c om * @param out The output stream to write to. * @param chart The chart to be written. * @param width The width of the image. * @param height The height of the image. * @throws IOException Thrown when an error occurs with the IO. */ public static void writeAsPDF(OutputStream out, JFreeChart chart, int width, int height) throws IOException { Document document = new Document(new Rectangle(width, height), 50, 50, 50, 50); document.addAuthor(""); document.addSubject(""); try { PdfWriter writer = PdfWriter.getInstance(document, out); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfTemplate tp = cb.createTemplate(width, height); java.awt.Graphics2D g2 = tp.createGraphics(width, height, new DefaultFontMapper()); chart.draw(g2, new java.awt.geom.Rectangle2D.Double(0, 0, width, height)); g2.dispose(); cb.addTemplate(tp, 0, 0); } catch (DocumentException de) { throw new IOException(de.getMessage()); } document.close(); }
From source file:pentaho.kettle.step.plugs.pdfout.PDFOutputGenerate.java
License:Apache License
public void generatePDF(String OutputFileName) throws IOException { if (Const.isWindows()) { if (OutputFileName.startsWith("file:///")) OutputFileName = OutputFileName.substring(8); OutputFileName = OutputFileName.replace("\\", "\\\\"); }/*from ww w .ja va2s . com*/ Document document = new Document(); PdfWriter writer; try { writer = PdfWriter.getInstance(document, new FileOutputStream(OutputFileName)); document.open(); document.add(new Paragraph("Hello Rishu Here !!")); /* * Setting up File Attributes - Document Description */ document.addAuthor("Rishu Shrivastava"); document.addCreationDate(); document.addCreator("Rishu"); document.addTitle("Set Attribute Example"); document.addSubject("An example to show how attributes can be added to pdf files."); document.close(); writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.metadata.UpdateModDate.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(ORIGINAL)); document.addTitle("Hello World example"); document.addSubject("This example shows how to add metadata"); document.addKeywords("Metadata, iText, XMP"); document.addCreator("My program using iText"); document.addAuthor("Bruno Lowagie"); writer.createXmpMetadata(); document.open(); document.add(new Paragraph("Hello World")); } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } document.close(); try { Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); } PdfReader reader; try { reader = new PdfReader(ORIGINAL); PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(MODIFIED)); stamper.close(); } catch (IOException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:se.idega.idegaweb.commune.school.business.StudentAddressLabelsWriter.java
License:Open Source License
/** * Creates PDF address labels for the specified school classes. *///from ww w . j a v a2 s . c o m protected MemoryFileBuffer getPDFBuffer(IWApplicationContext iwac, Collection receivers) throws Exception { this.business = getSchoolCommuneBusiness(iwac); this.userBusiness = getCommuneUserBusiness(iwac); IWResourceBundle iwrb = iwac.getIWMainApplication().getBundle(CommuneBlock.IW_BUNDLE_IDENTIFIER) .getResourceBundle(iwac.getApplicationSettings().getApplicationLocale()); MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, mos); document.addTitle("Student address labels"); document.addAuthor("Idega Reports"); document.addSubject("Student address labels"); document.open(); this.font = new Font(Font.HELVETICA, 9, Font.BOLD); int studentCount = 0; Iterator iter = receivers.iterator(); while (iter.hasNext()) { if (studentCount > 0 && studentCount % NR_OF_ADDRESSES_PER_PAGE == 0) { document.newPage(); } addAddress(writer, iwrb, (MailReceiver) iter.next(), studentCount++); } if (studentCount == 0) { throw new Exception("No students."); } document.close(); writer.setPdfVersion(PdfWriter.VERSION_1_2); buffer.setMimeType(MIME_PDF); return buffer; }
From source file:se.idega.idegaweb.commune.school.report.business.ReportPDFWriter.java
License:Open Source License
private MemoryFileBuffer getPDFBuffer() throws DocumentException { MemoryFileBuffer buffer = new MemoryFileBuffer(); MemoryOutputStream mos = new MemoryOutputStream(buffer); Document document = new Document(PageSize.A4, 50, 50, 50, 50); PdfWriter writer = PdfWriter.getInstance(document, mos); String titleKey = this._reportModel.getReportTitleLocalizationKey(); String title = localize(titleKey, titleKey); this._normalFont = new Font(Font.HELVETICA, 7, Font.NORMAL); this._boldFont = new Font(Font.HELVETICA, 7, Font.BOLD); document.addTitle(title);//from w ww . ja v a2 s .c om document.addAuthor("Agura IT Reports"); document.addSubject(title); document.open(); String dateString = new Date(System.currentTimeMillis()).toString(); document.add(new Phrase(title + " " + dateString + "\n\n", this._boldFont)); document.add(new Phrase("\n", this._boldFont)); int cols = this._reportModel.getColumnSize() + 1; Table table = new Table(cols); this._widths = new int[cols]; for (int i = 0; i < cols; i++) { this._widths[i] = 1; } table.setSpacing(1.5f); buildColumnHeaders(table); buildRowHeaders(table); buildReportCells(table); int totalWidth = 0; for (int i = 0; i < cols; i++) { this._widths[i] += 1; totalWidth += this._widths[i]; } int width = (100 * totalWidth) / 95; if (width > 100) { width = 100; } table.setWidth(width); table.setWidths(this._widths); document.add(table); document.close(); writer.setPdfVersion(PdfWriter.VERSION_1_2); return buffer; }