List of usage examples for com.lowagie.text Font NORMAL
int NORMAL
To view the source code for com.lowagie.text Font NORMAL.
Click Source Link
From source file:org.unitime.timetable.util.PdfFont.java
License:Open Source License
private static Font createFont(float size, boolean fixed, boolean bold, boolean italic) { String font = null;/*from ww w . ja v a2 s .c o m*/ if (fixed) font = ApplicationProperty.PdfFontFixed.value(); else if (bold) { if (italic) font = ApplicationProperty.PdfFontBoldItalic.value(); else font = ApplicationProperty.PdfFontBold.value(); } else if (italic) font = ApplicationProperty.PdfFontItalic.value(); else font = ApplicationProperty.PdfFontNormal.value(); if (font != null && !font.isEmpty()) { try { BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true); if (base != null) return new Font(base, size); } catch (Throwable t) { } } font = (fixed ? ApplicationProperty.PdfFontFixed.value() : ApplicationProperty.PdfFontNormal.value()); if (font != null && !font.isEmpty()) { try { BaseFont base = BaseFont.createFont(font, BaseFont.IDENTITY_H, true); if (base != null) return new Font(base, size, italic && bold ? Font.BOLDITALIC : italic ? Font.ITALIC : bold ? Font.BOLD : Font.NORMAL); } catch (Throwable t) { } } if (fixed) return FontFactory.getFont(bold ? italic ? FontFactory.COURIER_BOLDOBLIQUE : FontFactory.COURIER_BOLD : italic ? FontFactory.COURIER_OBLIQUE : FontFactory.COURIER, size); else return FontFactory .getFont(bold ? italic ? FontFactory.HELVETICA_BOLDOBLIQUE : FontFactory.HELVETICA_BOLD : italic ? FontFactory.HELVETICA_OBLIQUE : FontFactory.HELVETICA, size); }
From source file:org.webguitoolkit.ui.util.export.PDFTableExport.java
License:Apache License
/** * @param table/*w ww . j av a 2 s. co m*/ * @param footer * @param header * @return */ public PdfPTable pdfExport(Table table) { TableExportOptions exportOptions = table.getExportOptions(); boolean showOnlyDisplayed = exportOptions.isShowOnlyDisplayedColumns(); Font headfont = new Font(Font.UNDEFINED, Font.DEFAULTSIZE, Font.BOLD); Font bodyfont = new Font(exportOptions.getPdfFontSize(), exportOptions.getPdfFontSize(), Font.NORMAL); if (exportOptions.getPdfFontColour() != null) { Color fontColor = exportOptions.getPdfFontColour(); bodyfont.setColor(fontColor); headfont.setColor(fontColor); } List<ITableColumn> columns = getTableColumns(showOnlyDisplayed, table); int columnCount = 0; for (int i = 0; i < columns.size(); i++) { TableColumn c = (TableColumn) columns.get(i); //hide select checkbox column if (!c.isExporatble()) continue; columnCount++; } PdfPTable resulttable = new PdfPTable(columnCount); resulttable.setWidthPercentage(100f); if (StringUtils.isNotEmpty(exportOptions.getTableHeadline())) { PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableHeadline())); cell.setColspan(columns.size()); cell.setBackgroundColor(Color.lightGray); resulttable.addCell(cell); } for (int i = 0; i < columns.size(); i++) { TableColumn c = (TableColumn) columns.get(i); // hide select checkbox column if (!c.isExporatble()) continue; String cellData = TextService.getString(c.getTitle()); if (cellData.contains("<br/>") || cellData.contains("<br>")) { cellData = cellData.replaceAll("<br\\/>", "\\/"); cellData = cellData.replaceAll("<br>", "\\/"); } PdfPCell cell = new PdfPCell(new Paragraph((cellData), headfont)); cell.setBackgroundColor(Color.lightGray); resulttable.addCell(cell); } List tabledata = table.getDefaultModel().getFilteredList(); if (tabledata.isEmpty()) { for (int i = 0; i < columns.size(); i++) { resulttable.addCell(new PdfPCell((new Phrase("")))); } } for (Iterator it = tabledata.iterator(); it.hasNext();) { DataBag dbag = (DataBag) it.next(); for (int i = 0; i < columns.size(); i++) { TableColumn tableColumn = (TableColumn) columns.get(i); if (!tableColumn.isExporatble()) continue; logger.debug("property: " + tableColumn.getProperty()); IColumnRenderer renderer = tableColumn.getRenderer(); Converter converter = tableColumn.getConverter(); addObjectCell(bodyfont, resulttable, dbag, tableColumn, renderer, converter); } } if (StringUtils.isNotEmpty(exportOptions.getTableFooter())) { PdfPCell cell = new PdfPCell(new Paragraph(exportOptions.getTableFooter())); cell.setColspan(columnCount); cell.setBackgroundColor(Color.lightGray); resulttable.addCell(cell); } resulttable.setHeaderRows(1); return resulttable; }
From source file:oscar.eform.util.EFormPDFServlet.java
License:Open Source License
private void writeContent(Properties printCfg, Properties props, Properties measurements, float height, PdfContentByte cb) throws Exception { for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) { StringBuilder temp = new StringBuilder(e.nextElement().toString()); String[] cfgVal = printCfg.getProperty(temp.toString()).split(" *, *"); String[] fontType = null; int fontFlags = 0; if (cfgVal[4].indexOf(";") > -1) { fontType = cfgVal[4].split(";"); if (fontType[1].trim().equals("italic")) fontFlags = Font.ITALIC; else if (fontType[1].trim().equals("bold")) fontFlags = Font.BOLD; else if (fontType[1].trim().equals("bolditalic")) fontFlags = Font.BOLDITALIC; else/*from ww w .ja va2 s . co m*/ fontFlags = Font.NORMAL; } else { fontFlags = Font.NORMAL; fontType = new String[] { cfgVal[4].trim() }; } String encoding = null; if (fontType[0].trim().equals("BaseFont.HELVETICA")) { fontType[0] = BaseFont.HELVETICA; encoding = BaseFont.CP1252; //latin1 encoding } else if (fontType[0].trim().equals("BaseFont.HELVETICA_OBLIQUE")) { fontType[0] = BaseFont.HELVETICA_OBLIQUE; encoding = BaseFont.CP1252; } else if (fontType[0].trim().equals("BaseFont.ZAPFDINGBATS")) { fontType[0] = BaseFont.ZAPFDINGBATS; encoding = BaseFont.ZAPFDINGBATS; } else { fontType[0] = BaseFont.COURIER; encoding = BaseFont.CP1252; } BaseFont bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED); String propValue = props.getProperty(temp.toString()); //if not in regular config then check measurements if (propValue == null) { propValue = measurements.getProperty(temp.toString(), ""); } ColumnText ct = new ColumnText(cb); // write in a rectangle area if (cfgVal.length >= 9) { Font font = new Font(bf, Integer.parseInt(cfgVal[5].trim()), fontFlags); ct.setSimpleColumn(Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), Integer.parseInt(cfgVal[7].trim()), (height - Integer.parseInt(cfgVal[8].trim())), Integer.parseInt(cfgVal[9].trim()), (cfgVal[0].trim().equals("left") ? Element.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? Element.ALIGN_RIGHT : Element.ALIGN_CENTER))); ct.setText(new Phrase(12, propValue, font)); ct.go(); continue; } // draw line directly if (temp.toString().startsWith("__$line")) { cb.setRGBColorStrokeF(0f, 0f, 0f); cb.setLineWidth(Float.parseFloat(cfgVal[4].trim())); cb.moveTo(Float.parseFloat(cfgVal[0].trim()), Float.parseFloat(cfgVal[1].trim())); cb.lineTo(Float.parseFloat(cfgVal[2].trim()), Float.parseFloat(cfgVal[3].trim())); cb.stroke(); } else if (temp.toString().startsWith("__")) { cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), (cfgVal.length >= 7 ? (cfgVal[6].trim()) : propValue), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } else { // write prop text cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), (cfgVal.length >= 7 ? ((propValue.equals("") ? "" : cfgVal[6].trim())) : propValue), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } } }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
/** * Prints the consultation request./* www.ja v a2s. 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.EctConsultationFormRequestPrintPdf.java
License:Open Source License
private float addDynamicPositionedText(String name, String text, float dynamicHeight, EctConsultationFormRequestUtil reqForm) throws DocumentException, IOException { if (text != null && text.length() > 0) { Font boldFont = new Font(bf, FONTSIZE, Font.BOLD); Font font = new Font(bf, FONTSIZE, Font.NORMAL); float lineCount = (name.length() + text.length()) / 100; // if there is not enough room on the page for the text start on the next page if ((height - 264 - dynamicHeight - lineCount * LINEHEIGHT) < LINEHEIGHT * 3) { nextPage(reqForm);// ww w . j av a2 s .c om dynamicHeight = LINEHEIGHT - 152; } ct.setSimpleColumn(new Float(85), height - 264 - dynamicHeight - lineCount * LINEHEIGHT, new Float(526), height - 250 - dynamicHeight, LINEHEIGHT, Element.ALIGN_LEFT); ct.addText(new Phrase(name, boldFont)); ct.addText(new Phrase(text, font)); ct.go(); dynamicHeight += lineCount * LINEHEIGHT + LINEHEIGHT * 2; } return dynamicHeight; }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.EctConsultationFormRequestPrintPdf.java
License:Open Source License
private void setAppointmentInfo(EctConsultationFormRequestUtil reqForm) throws DocumentException { printClinicData(reqForm);//from w ww . j av a2 s .c o m Font font = new Font(bf, FONTSIZE, Font.NORMAL); // Set consultant info cb.beginText(); cb.setFontAndSize(bf, FONTSIZE); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.referalDate, 190, height - 112, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.urgency.equals("1") ? "Urgent" : (reqForm.urgency.equals("2") ? "Non-Urgent" : "Return"), 190, height - 125, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getServiceName(reqForm.service), 190, height - 139, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.getSpecailistsName(reqForm.specialist), 190, height - 153, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specPhone, 190, height - 166, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.specFax, 190, height - 181, 0); cb.endText(); ct.setSimpleColumn(new Float(190), height - 223, new Float(290), height - 181, LINEHEIGHT, Element.ALIGN_LEFT); ct.addText(new Phrase(reqForm.specAddr.replaceAll("<br>", "\n"), font)); ct.go(); // Set patient info cb.beginText(); cb.setFontAndSize(bf, FONTSIZE); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientName, 385, height - 112, 0); cb.endText(); ct.setSimpleColumn(new Float(385), height - 153, new Float(585), height - 112, LINEHEIGHT, Element.ALIGN_LEFT); ct.addText(new Phrase(reqForm.patientAddress.replaceAll("<br>", " "), font)); ct.go(); cb.beginText(); cb.setFontAndSize(bf, FONTSIZE); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientPhone, 385, height - 166, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientDOB, 385, height - 181, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, (reqForm.patientHealthCardType + " " + reqForm.patientHealthNum + " " + reqForm.patientHealthCardVersionCode).trim(), 440, height - 195, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.appointmentHour + ":" + reqForm.appointmentMinute + " " + reqForm.appointmentPm + " " + reqForm.appointmentDay + "/" + reqForm.appointmentMonth + "/" + reqForm.appointmentYear, 440, height - 208, 0); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, reqForm.patientChartNo, 385, height - 222, 0); cb.endText(); }
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();/*from w w w.j ava 2 s .c o m*/ //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.oscarLab.ca.all.pageUtil.LabPDFCreator.java
License:Open Source License
private void addLabCategory(String header) throws DocumentException { float[] mainTableWidths = { 5f, 3f, 1f, 3f, 2f, 4f, 2f }; PdfPTable table = new PdfPTable(mainTableWidths); table.setHeaderRows(3);//from w ww. ja v a 2 s. co m table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(); // category name cell.setPadding(3); cell.setPhrase(new Phrase(" ")); cell.setBorder(0); cell.setColspan(7); table.addCell(cell); cell.setBorder(15); cell.setPadding(3); cell.setColspan(2); cell.setPhrase(new Phrase(header.replaceAll("<br\\s*/*>", "\n"), new Font(bf, 12, Font.BOLD))); table.addCell(cell); cell.setPhrase(new Phrase(" ")); cell.setBorder(0); cell.setColspan(5); table.addCell(cell); // table headers cell.setColspan(1); cell.setBorder(15); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(new Color(210, 212, 255)); cell.setPhrase(new Phrase("Test Name(s)", boldFont)); table.addCell(cell); cell.setPhrase(new Phrase("Result", boldFont)); table.addCell(cell); cell.setPhrase(new Phrase("Abn", boldFont)); table.addCell(cell); cell.setPhrase(new Phrase("Reference Range", boldFont)); table.addCell(cell); cell.setPhrase(new Phrase("Units", boldFont)); table.addCell(cell); cell.setPhrase(new Phrase("Date/Time Completed", boldFont)); table.addCell(cell); cell.setPhrase(new Phrase("Status", boldFont)); table.addCell(cell); // add test results int obrCount = handler.getOBRCount(); int linenum = 0; cell.setBorder(12); cell.setBorderColor(Color.BLACK); // cell.setBorderColor(Color.WHITE); cell.setBackgroundColor(new Color(255, 255, 255)); if (handler.getMsgType().equals("MEDVUE")) { //cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPhrase(new Phrase(handler.getRadiologistInfo(), boldFont)); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell.setPaddingLeft(100); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPhrase(new Phrase(handler.getOBXComment(1, 1, 1).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); } else { for (int j = 0; j < obrCount; j++) { boolean obrFlag = false; int obxCount = handler.getOBXCount(j); for (int k = 0; k < obxCount; k++) { String obxName = handler.getOBXName(j, k); if (!handler.getOBXResultStatus(j, k).equals("TDIS")) { // ensure that the result is a real result if ((!handler.getOBXResultStatus(j, k).equals("DNS") && !obxName.equals("") && handler.getObservationHeader(j, k).equals(header)) || (handler.getMsgType().equals("EPSILON") && handler.getOBXIdentifier(j, k).equals(header) && !obxName.equals("")) || (handler.getMsgType().equals("PFHT") && !obxName.equals("") && handler.getObservationHeader(j, k).equals(header))) { // <<-- DNS only needed for // MDS messages String obrName = handler.getOBRName(j); // add the obrname if necessary if (!obrFlag && !obrName.equals("") && !(obxName.contains(obrName) && obxCount < 2)) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPhrase(new Phrase(obrName, boldFont)); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); cell.setColspan(1); obrFlag = true; } // add the obx results and info Font lineFont = new Font(bf, 8, Font.NORMAL, getTextColor(handler.getOBXAbnormalFlag(j, k))); // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPhrase(new Phrase((obrFlag ? " " : "") + obxName, lineFont)); table.addCell(cell); cell.setPhrase(new Phrase(handler.getOBXResult(j, k).replaceAll("<br\\s*/*>", "\n"), lineFont)); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(cell); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPhrase(new Phrase( (handler.isOBXAbnormal(j, k) ? handler.getOBXAbnormalFlag(j, k) : "N"), lineFont)); table.addCell(cell); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPhrase(new Phrase(handler.getOBXReferenceRange(j, k), lineFont)); table.addCell(cell); cell.setPhrase(new Phrase(handler.getOBXUnits(j, k), lineFont)); table.addCell(cell); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPhrase(new Phrase(handler.getTimeStamp(j, k), lineFont)); table.addCell(cell); cell.setPhrase(new Phrase(handler.getOBXResultStatus(j, k), lineFont)); table.addCell(cell); if (!handler.getMsgType().equals("PFHT")) { // add obx comments if (handler.getOBXCommentCount(j, k) > 0) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPaddingLeft(100); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) { cell.setPhrase(new Phrase( handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); } cell.setPadding(3); cell.setColspan(1); } } // if (DNS) } else if ((handler.getMsgType().equals("EPSILON") && handler.getOBXIdentifier(j, k).equals(header) && obxName.equals("")) || (handler.getMsgType().equals("PFHT") && obxName.equals("") && handler.getObservationHeader(j, k).equals(header))) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPaddingLeft(100); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPhrase( new Phrase(handler.getOBXResult(j, k).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); cell.setPadding(3); cell.setColspan(1); } if (handler.getMsgType().equals("PFHT") && !handler.getNteForOBX(j, k).equals("") && handler.getNteForOBX(j, k) != null) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPaddingLeft(100); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.setPhrase( new Phrase(handler.getNteForOBX(j, k).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); cell.setPadding(3); cell.setColspan(1); if (handler.getOBXCommentCount(j, k) > 0) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPaddingLeft(100); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) { cell.setPhrase(new Phrase( handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); } cell.setPadding(3); cell.setColspan(1); } } } else { if (handler.getOBXCommentCount(j, k) > 0) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPaddingLeft(100); cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); for (int l = 0; l < handler.getOBXCommentCount(j, k); l++) { cell.setPhrase(new Phrase( handler.getOBXComment(j, k, l).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); } cell.setPadding(3); cell.setColspan(1); } } // if (!handler.getOBXResultStatus(j, k).equals("TDIS")) } if (!handler.getMsgType().equals("PFHT")) { // add obr comments if (handler.getObservationHeader(j, 0).equals(header)) { cell.setColspan(7); cell.setHorizontalAlignment(Element.ALIGN_LEFT); for (int k = 0; k < handler.getOBRCommentCount(j); k++) { // the obrName should only be set if it has not been // set already which will only have occured if the // obx name is "" or if it is the same as the obr name if (!obrFlag && handler.getOBXName(j, 0).equals("")) { // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPhrase(new Phrase(handler.getOBRName(j), boldFont)); table.addCell(cell); obrFlag = true; } // cell.setBackgroundColor(getHighlightColor(linenum)); linenum++; cell.setPaddingLeft(100); cell.setPhrase( new Phrase(handler.getOBRComment(j, k).replaceAll("<br\\s*/*>", "\n"), font)); table.addCell(cell); cell.setPadding(3); } cell.setColspan(1); } } } // for (j) } // if (isMEDVUE) document.add(table); }
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();// w ww . j ava 2 s . c om //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:permit.InvoicePdf.java
License:Open Source License
/** * handles the letter header/*from www .ja v a 2 s .c om*/ */ PdfPTable getHeader() { // String str = ""; String spacer = " "; PdfPTable headTable = null; try { // // for http url use // Image image = Image.getInstance(url + "js/images/city_logo3.jpg"); Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); float[] widths = { 25f, 40f, 35f }; // percentages headTable = new PdfPTable(widths); headTable.setWidthPercentage(100); headTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); headTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); image.scalePercent(15f); PdfPCell cell = new PdfPCell(image); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); headTable.addCell(cell); // float[] width = { 33f }; PdfPTable midTable = new PdfPTable(width); midTable.setWidthPercentage(33); midTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); midTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); Phrase phrase = new Phrase(); Chunk ch = new Chunk("City of Bloomington ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("Planning and Transportation Department ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); midTable.addCell(cell); // headTable.addCell(midTable); // PdfPTable rightTable = new PdfPTable(width); rightTable.setWidthPercentage(33); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); rightTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); phrase = new Phrase(); ch = new Chunk("401 N Morton St Suite 130 ", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("PO Box 100 \nBloomington, IN 47404", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // phrase = new Phrase(); ch = new Chunk("\n Phone: (812) 349-3423\nFax (812) 349-3520\nEmail: planning@bloomington.in.gov", fntb); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); headTable.addCell(rightTable); } catch (Exception ex) { logger.error(ex); } return headTable; }