List of usage examples for com.lowagie.text PageSize LETTER
Rectangle LETTER
To view the source code for com.lowagie.text PageSize LETTER.
Click Source Link
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
public float getWidth() { float totalWidth = 0f; for (int i = 0; i < widths.length; i++) totalWidth += 25f + widths[i];/*from ww w.j a v a 2 s . c om*/ totalWidth = Math.max(PageSize.LETTER.getHeight(), totalWidth); return totalWidth; }
From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java
License:Open Source License
public void export(OutputStream out) throws Exception { int nrCols = getNrColumns(); iDocument = (iForm.getDispMode() == sDispModeInRowHorizontal || iForm.getDispMode() == sDispModeInRowVertical ? new Document( new Rectangle(Math.max(PageSize.LETTER.getWidth(), 60.0f + 100.0f * nrCols), Math.max(PageSize.LETTER.getHeight(), 60.0f + 150f * nrCols)).rotate(), 30, 30, 30, 30) : new Document( new Rectangle(Math.max(PageSize.LETTER.getWidth(), 60.0f + 100.0f * nrCols), Math.max(PageSize.LETTER.getHeight(), 60.0f + 150f * nrCols)), 30, 30, 30, 30)); PdfEventHandler.initFooter(iDocument, out); iDocument.open();/*from w w w .ja v a 2s . co m*/ printTable(); printLegend(); iDocument.close(); }
From source file:oscar.eform.util.EFormPDFServlet.java
License:Open Source License
private void addDocumentProps(Document document, String title, Properties props) { document.addTitle(title);//w w w . j av a 2 s . c om document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); // 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 final String PAGESIZE = "printPageSize"; Rectangle pageSize = PageSize.LETTER; if ("PageSize.HALFLETTER".equals(props.getProperty(PAGESIZE))) pageSize = PageSize.HALFLETTER; if ("PageSize.A6".equals(props.getProperty(PAGESIZE))) pageSize = PageSize.A6; document.setPageSize(pageSize); document.open(); }
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 ww . j a v a2s . 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:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
/** * Prints the consultation request.//from w w w . j a v a2 s . c o m * @throws IOException when an error with the output stream occurs * @throws DocumentException when an error in document construction occurs */ public void printPdf() throws IOException, DocumentException { // Create the document we are going to write to document = new Document(); PdfWriter.getInstance(document, os); document.setPageSize(PageSize.LETTER); document.addTitle(getResource("msgConsReq")); document.addCreator("OSCAR"); document.open(); // Create the fonts that we are going to use bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); headerFont = new Font(bf, 14, Font.BOLD); infoFont = new Font(bf, 12, Font.NORMAL); font = new Font(bf, 9, Font.NORMAL); boldFont = new Font(bf, 10, Font.BOLD); bigBoldFont = new Font(bf, 12, Font.BOLD); createConsultationRequest(); document.close(); }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ImagePDFCreator.java
License:Open Source License
/** * Prints the consultation request.//from ww w . ja v a 2s . c om * @throws IOException when an error with the output stream occurs * @throws DocumentException when an error in document construction occurs */ public void printPdf() throws IOException, DocumentException { Image image; try { image = Image.getInstance((String) request.getAttribute("imagePath")); } catch (Exception e) { logger.error("Unexpected error:", e); throw new DocumentException(e); } // Create the document we are going to write to document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, os); document.setPageSize(PageSize.LETTER); ResourceBundle.getBundle("oscarResources", request.getLocale()) .getString("oscarEncounter.oscarConsultationRequest.consultationFormPrint.msgImage"); document.addCreator("OSCAR"); document.open(); int type = image.getOriginalType(); if (type == Image.ORIGINAL_TIFF) { // The following is composed of code from com.lowagie.tools.plugins.Tiff2Pdf modified to create the // PDF in memory instead of on disk RandomAccessFileOrArray ra = new RandomAccessFileOrArray((String) request.getAttribute("imagePath")); int comps = TiffImage.getNumberOfPages(ra); boolean adjustSize = false; PdfContentByte cb = writer.getDirectContent(); for (int c = 0; c < comps; ++c) { Image img = TiffImage.getTiffImage(ra, c + 1); if (img != null) { if (adjustSize) { document.setPageSize(new Rectangle(img.getScaledWidth(), img.getScaledHeight())); document.newPage(); img.setAbsolutePosition(0, 0); } else { if (img.getScaledWidth() > 500 || img.getScaledHeight() > 700) { img.scaleToFit(500, 700); } img.setAbsolutePosition(20, 20); document.newPage(); document.add( new Paragraph((String) request.getAttribute("imageTitle") + " - page " + (c + 1))); } cb.addImage(img); } } ra.close(); } else { PdfContentByte cb = writer.getDirectContent(); if (image.getScaledWidth() > 500 || image.getScaledHeight() > 700) { image.scaleToFit(500, 700); } image.setAbsolutePosition(20, 20); cb.addImage(image); } document.close(); }
From source file:oscar.oscarLab.ca.all.pageUtil.LabPDFCreator.java
License:Open Source License
public void printPdf() throws IOException, DocumentException { // check that we have data to print if (handler == null) throw new DocumentException(); //response.setContentType("application/pdf"); //octet-stream //response.setHeader("Content-Disposition", "attachment; filename=\""+handler.getPatientName().replaceAll("\\s", "_")+"_LabReport.pdf\""); //Create the document we are going to write to document = new Document(); //PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream()); PdfWriter writer = PdfWriter.getInstance(document, os); //Set page event, function onEndPage will execute each time a page is finished being created writer.setPageEvent(this); document.setPageSize(PageSize.LETTER); document.addTitle("Title of the Document"); document.addCreator("OSCAR"); document.open();/* ww w . ja va 2 s .c om*/ //Create the fonts that we are going to use bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); font = new Font(bf, 9, Font.NORMAL); boldFont = new Font(bf, 10, Font.BOLD); redFont = new Font(bf, 9, Font.NORMAL, Color.RED); // add the header table containing the patient and lab info to the document createInfoTable(); // add the tests and test info for each header ArrayList<String> headers = handler.getHeaders(); for (int i = 0; i < headers.size(); i++) addLabCategory(headers.get(i)); // add end of report table PdfPTable table = new PdfPTable(1); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.setPhrase(new Phrase(" ")); table.addCell(cell); cell.setBorder(15); cell.setBackgroundColor(new Color(210, 212, 255)); cell.setPhrase(new Phrase("END OF REPORT", boldFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); document.add(table); document.close(); os.flush(); }
From source file:oscar.oscarPrevention.pageUtil.PreventionPrintPdf.java
License:Open Source License
public void printPdf(String[] headerIds, HttpServletRequest request, OutputStream outputStream) throws IOException, DocumentException { //make sure we have data to print //String[] headerIds = request.getParameterValues("printHP"); if (headerIds == null) throw new DocumentException(); //Create the document we are going to write to document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, outputStream); document.setPageSize(PageSize.LETTER); document.open();//from ww w. ja va2 s . c o m //Create the font we are going to print to BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); Font font = new Font(bf, FONTSIZE, Font.NORMAL); float leading = font.getCalculatedLeading(LINESPACING); //set up document title and header String title = "Preventions for " + request.getParameter("nameAge"); String hin = "HIN: " + request.getParameter("hin"); String mrp = request.getParameter("mrp"); if (mrp != null) { Properties prop = (Properties) request.getSession().getAttribute("providerBean"); mrp = "MRP: " + prop.getProperty(mrp, "unknown"); } ClinicData clinicData = new ClinicData(); clinicData.refreshClinicData(); String[] clinic = new String[] { clinicData.getClinicName(), clinicData.getClinicAddress(), clinicData.getClinicCity() + ", " + clinicData.getClinicProvince(), clinicData.getClinicPostal(), clinicData.getClinicPhone(), title, hin, mrp }; //Header will be printed at top of every page beginning with p2 Phrase headerPhrase = new Phrase(LEADING, title, font); HeaderFooter header = new HeaderFooter(headerPhrase, false); header.setAlignment(HeaderFooter.ALIGN_CENTER); document.setHeader(header); //Write title with top and bottom borders on p1 cb = writer.getDirectContent(); cb.setColorStroke(new Color(0, 0, 0)); cb.setLineWidth(0.5f); cb.moveTo(document.left(), document.top()); cb.lineTo(document.right(), document.top()); cb.stroke(); cb.setFontAndSize(bf, FONTSIZE); upperYcoord = document.top() - (font.getCalculatedLeading(LINESPACING) * 2f); cb.beginText(); for (int idx = 0; idx < clinic.length; ++idx) { cb.showTextAligned(PdfContentByte.ALIGN_CENTER, clinic[idx], document.right() / 2f, upperYcoord, 0f); upperYcoord -= font.getCalculatedLeading(LINESPACING); } cb.endText(); cb.moveTo(document.left(), upperYcoord); cb.lineTo(document.right(), upperYcoord); cb.stroke(); //get top y-coord for starting to print columns upperYcoord = cb.getYTLM() - font.getCalculatedLeading(LINESPACING * 2f); int subIdx; String preventionHeader, procedureAge, procedureDate; //1 - obtain number of lines of incoming prevention data numLines = 0; for (int idx = 0; idx < headerIds.length; ++idx) { ++numLines; subIdx = 0; while (request.getParameter("preventProcedureAge" + headerIds[idx] + "-" + subIdx) != null) { ++subIdx; numLines += 3; } numLines += 2; } //2 - calculate max num of lines a page can hold and number of pages of data we have pageHeight = upperYcoord - document.bottom(); maxLines = (int) Math.floor(pageHeight / (font.getCalculatedLeading(LINESPACING) + 4d)); numPages = (int) Math.ceil(numLines / ((double) maxLines * NUMCOLS)); //3 - Start the column ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.bottom(), document.right() / 2f, upperYcoord); linesToBeWritten = linesWritten = 0; boolean pageBreak = false; curPage = 1; totalLinesWritten = 0; //add promotext to current page addPromoText(); //if we have > 1 element but less than a page of data, shrink maxLines so we can try to balance text in columns if (headerIds.length > 1) { if (curPage == numPages) { maxLines = numLines / NUMCOLS; } } //now we can start to print the prevention data for (int idx = 0; idx < headerIds.length; ++idx) { linesToBeWritten = 4; //minimum lines for header and one prevention item pageBreak = checkColumnFill(ct, "", font, pageBreak); //if necessary break before we print prevention header preventionHeader = request.getParameter("preventionHeader" + headerIds[idx]); Phrase procHeader = new Phrase(LEADING, "Prevention " + preventionHeader + "\n", font); ct.addText(procHeader); subIdx = 0; while ((procedureAge = request .getParameter("preventProcedureAge" + headerIds[idx] + "-" + subIdx)) != null) { procedureDate = request.getParameter("preventProcedureDate" + headerIds[idx] + "-" + subIdx); linesToBeWritten = 3; pageBreak = checkColumnFill(ct, preventionHeader, font, pageBreak); Phrase procedure = new Phrase(LEADING, " " + procedureAge + "\n", font); procedure.add(" " + procedureDate + "\n\n"); ct.addText(procedure); ct.go(); linesWritten += ct.getLinesWritten(); totalLinesWritten += ct.getLinesWritten(); ++subIdx; } } ColumnText.showTextAligned(cb, Phrase.ALIGN_CENTER, new Phrase("-" + curPage + "-"), document.right() / 2f, document.bottom() - (document.bottomMargin() / 2f), 0f); document.close(); }
From source file:oscar.oscarPrevention.pageUtil.PreventionPrintPdf.java
License:Open Source License
private void addPromoText() throws DocumentException, IOException { if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) { cb.beginText();/* w w w .j av a 2s .c o m*/ cb.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED), 6); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), PageSize.LETTER.getWidth() / 2, 5, 0); cb.endText(); } }
From source file:questions.directcontent.InterpretOCR.java
public static void main(String[] args) throws IOException, DocumentException { Document document = new Document(PageSize.LETTER); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open();/* w w w . j ava 2s . c o m*/ PdfContentByte cb = writer.getDirectContent(); BaseFont font = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); cb.beginText(); cb.setFontAndSize(font, 12); String line; String word; @SuppressWarnings("unused") float llx, lly, urx, ury; StringTokenizer tokenizer; BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(RESOURCE))); while ((line = reader.readLine()) != null) { tokenizer = new StringTokenizer(line); while (tokenizer.hasMoreTokens()) { tokenizer.nextToken(); word = tokenizer.nextToken(); llx = Float.parseFloat(tokenizer.nextToken() + "f") / 10; lly = document.top() - Float.parseFloat(tokenizer.nextToken() + "f") / 10; urx = Float.parseFloat(tokenizer.nextToken() + "f") / 10; ury = document.top() - Float.parseFloat(tokenizer.nextToken() + "f") / 10; cb.showTextAligned(Element.ALIGN_LEFT, word, (llx + urx) / 2, lly, 0); } } cb.endText(); document.close(); }