List of usage examples for com.lowagie.text Element ALIGN_LEFT
int ALIGN_LEFT
To view the source code for com.lowagie.text Element ALIGN_LEFT.
Click Source Link
From source file:org.openswing.swing.export.java.ExportToPDF14.java
License:Open Source License
/** * Append current row to result./*from ww w. j a v a 2s .co m*/ * @return current row to append */ private void appendRow(Document document, ExportOptions exportOptions, PdfPTable table, Object vo, GridExportOptions opt, Hashtable gettersMethods, SimpleDateFormat sdf, SimpleDateFormat sdatf, SimpleDateFormat stf, int row, int tableType // 0 = header, 1 = body, 2 = footer ) throws Throwable { int type; String aName = null; Method getter = null; Class clazz = null; Object obj = null; for (int i = 0; i < opt.getExportColumns().size(); i++) { // value = ((Method)gettersMethods.get(opt.getExportAttrColumns().get(i))).invoke(vo,new Object[0]); clazz = vo.getClass(); obj = vo; aName = opt.getExportAttrColumns().get(i).toString(); // check if the specified attribute is a composed attribute and there exist inner v.o. to instantiate... while (aName.indexOf(".") != -1) { try { getter = clazz.getMethod( "get" + aName.substring(0, 1).toUpperCase() + aName.substring(1, aName.indexOf(".")), new Class[0]); } catch (NoSuchMethodException ex2) { getter = clazz.getMethod( "is" + aName.substring(0, 1).toUpperCase() + aName.substring(1, aName.indexOf(".")), new Class[0]); } aName = aName.substring(aName.indexOf(".") + 1); clazz = getter.getReturnType(); obj = getter.invoke(obj, new Object[0]); if (obj == null) break; } try { getter = clazz.getMethod("get" + aName.substring(0, 1).toUpperCase() + aName.substring(1), new Class[0]); } catch (NoSuchMethodException ex2) { getter = clazz.getMethod("is" + aName.substring(0, 1).toUpperCase() + aName.substring(1), new Class[0]); } if (obj != null) obj = getter.invoke(obj, new Object[0]); if (obj != null) { if (obj instanceof Date || obj instanceof java.util.Date || obj instanceof java.sql.Timestamp) { type = ((Integer) opt.getColumnsType().get(opt.getExportAttrColumns().get(i))).intValue(); if (type == opt.TYPE_DATE) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(sdf.format((java.util.Date) obj), (Font) exportOptions.getExportToPDFAdapter().getRowFont(aName))); } else if (type == opt.TYPE_DATE_TIME) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(sdatf.format((java.util.Date) obj), (Font) exportOptions.getExportToPDFAdapter().getRowFont(aName))); } else if (type == opt.TYPE_TIME) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(stf.format((java.util.Date) obj), (Font) exportOptions.getExportToPDFAdapter().getRowFont(aName))); } } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase(obj.toString(), (Font) exportOptions.getExportToPDFAdapter().getRowFont(aName))); } } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase("", (Font) exportOptions.getExportToPDFAdapter().getRowFont(aName))); } } if (opt.getCallbacks() != null) { if (tableType == 0) processComponent(table, opt.getExportColumns().size(), document, exportOptions, opt.getCallbacks().getComponentPerRowInHeader((ValueObject) vo, row)); else if (tableType == 1) processComponent(table, opt.getExportColumns().size(), document, exportOptions, opt.getCallbacks().getComponentPerRow((ValueObject) vo, row)); else if (tableType == 2) processComponent(table, opt.getExportColumns().size(), document, exportOptions, opt.getCallbacks().getComponentPerRowInFooter((ValueObject) vo, row)); } }
From source file:org.openswing.swing.export.java.ExportToPDF15.java
License:Open Source License
private void prepareGenericComponent(PdfPTable parentTable, int parentTableCols, Document document, ExportOptions exportOptions, ComponentExportOptions opt) throws Throwable { if (opt.getCellsContent() == null || opt.getCellsContent().length == 0) return;/*w ww. ja v a 2 s .com*/ int cols = opt.getCellsContent()[0].length; Object[] row = null; Object obj = null; SimpleDateFormat sdatf = new SimpleDateFormat(exportOptions.getDateTimeFormat()); int[] headerwidths = new int[cols]; for (int i = 0; i < headerwidths.length; i++) headerwidths[i] = (int) PageSize.A4.getWidth() / cols; PdfPTable table = new PdfPTable(cols); table.setWidths(headerwidths); table.setWidthPercentage(90); table.getDefaultCell().setBorderWidth(2); table.getDefaultCell().setBorderColor(Color.black); table.getDefaultCell().setGrayFill(exportOptions.getExportToPDFAdapter().getHeaderGrayFill()); table.getDefaultCell().setPadding(3); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE); table.setHeaderRows(0); table.getDefaultCell().setBorderWidth(0); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setVerticalAlignment(Element.ALIGN_TOP); for (int i = 0; i < opt.getCellsContent().length; i++) { row = opt.getCellsContent()[i]; for (int j = 0; j < row.length; j++) { obj = row[j]; if (obj != null) { if (obj instanceof Date || obj instanceof java.util.Date || obj instanceof java.sql.Timestamp) { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(sdatf.format((java.util.Date) obj), (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, obj))); } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase(obj.toString(), (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, obj))); } } else { table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(new Phrase("", (Font) exportOptions.getExportToPDFAdapter().getGenericComponentFont(i, j, null))); } } } if (parentTable != null) { PdfPCell cell = new PdfPCell(table); cell.setColspan(parentTableCols); parentTable.addCell(cell); } else document.add(table); }
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); }// ww w . j a v a 2 s .c om 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.oscarehr.casemgmt.print.OscarChartPrinter.java
License:Open Source License
public void printDocHeaderFooter() throws DocumentException { String headerTitle = demographic.getFormattedName() + " " + demographic.getAge() + " " + demographic.getSex() + " DOB:" + demographic.getFormattedDob(); //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); String title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) request.getAttribute("demoName") + "\n"; String gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) request.getAttribute("demoSex") + "\n"; String dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) request.getAttribute("demoDOB") + "\n"; String age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) request.getAttribute("demoAge") + "\n"; String mrp = propResource.getString("oscarEncounter.pdfPrint.mrp") + " " + (String) request.getAttribute("mrp") + "\n"; String[] info = new String[] { title, gender, dob, age, mrp }; ClinicData clinicData = new ClinicData(); clinicData.refreshClinicData();/*w ww. jav a 2s.c o m*/ String[] clinic = new String[] { clinicData.getClinicName(), clinicData.getClinicAddress(), clinicData.getClinicCity() + ", " + clinicData.getClinicProvince(), clinicData.getClinicPostal(), clinicData.getClinicPhone() }; if (newPage) { document.newPage(); newPage = false; } //Header will be printed at top of every page beginning with p2 Phrase headerPhrase = new Phrase(LEADING, headerTitle, boldFont); HeaderFooter header = new HeaderFooter(headerPhrase, false); header.setAlignment(HeaderFooter.ALIGN_CENTER); document.setHeader(header); getDocument().add(headerPhrase); getDocument().add(new Phrase("\n")); Paragraph p = new Paragraph("Tel:" + demographic.getPhone(), getFont()); p.setAlignment(Paragraph.ALIGN_LEFT); // getDocument().add(p); Paragraph p2 = new Paragraph("Date of Visit: ", getFont()); p2.setAlignment(Paragraph.ALIGN_RIGHT); // getDocument().add(p); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPCell cell1 = new PdfPCell(p); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(p2); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); cell2.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); getDocument().add(table); table = new PdfPTable(3); table.setWidthPercentage(100f); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); cell1 = new PdfPCell(getParagraph("Signed Provider:" + ((signingProvider != null) ? signingProvider : ""))); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(getParagraph("RFR:")); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBorder(PdfPCell.NO_BORDER); PdfPCell cell3 = new PdfPCell(getParagraph("Ref:")); cell3.setHorizontalAlignment(Element.ALIGN_RIGHT); cell3.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); getDocument().add(table); //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() - (font.getCalculatedLeading(LINESPACING) * 5f)); cb.lineTo(document.right(), document.top() - (font.getCalculatedLeading(LINESPACING) * 5f)); cb.stroke(); }
From source file:org.oscarehr.casemgmt.print.OscarChartPrinter.java
License:Open Source License
private PdfPCell generalCellForApptHistory(String text) { Paragraph p = new Paragraph(text, getFont()); p.setAlignment(Paragraph.ALIGN_LEFT); PdfPCell cell1 = new PdfPCell(p); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); return cell1; }
From source file:org.oscarehr.common.service.PdfRecordPrinter.java
License:Open Source License
public void printDocHeaderFooter() throws DocumentException { document.resetHeader();/*from w w w .j av a 2 s. c o m*/ document.resetFooter(); //document.resetPageCount(); String headerTitle = demographic.getFormattedName() + " " + demographic.getAge() + " " + demographic.getSex() + " DOB:" + demographic.getFormattedDob(); //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); String title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) request.getAttribute("demoName") + "\n"; String gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) request.getAttribute("demoSex") + "\n"; String dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) request.getAttribute("demoDOB") + "\n"; String age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) request.getAttribute("demoAge") + "\n"; String mrp = propResource.getString("oscarEncounter.pdfPrint.mrp") + " " + (String) request.getAttribute("mrp") + "\n"; String[] info = new String[] { title, gender, dob, age, mrp }; ClinicData clinicData = new ClinicData(); clinicData.refreshClinicData(); String[] clinic = new String[] { clinicData.getClinicName(), clinicData.getClinicAddress(), clinicData.getClinicCity() + ", " + clinicData.getClinicProvince(), clinicData.getClinicPostal(), clinicData.getClinicPhone() }; if (newPage) { document.newPage(); newPage = false; } //Header will be printed at top of every page beginning with p2 Phrase headerPhrase = new Phrase(LEADING, headerTitle, boldFont); /* HeaderFooter header = new HeaderFooter(headerPhrase,false); header.setAlignment(HeaderFooter.ALIGN_CENTER); document.setHeader(header); */ getDocument().add(headerPhrase); getDocument().add(new Phrase("\n")); Paragraph p = new Paragraph("Tel:" + demographic.getPhone(), getFont()); p.setAlignment(Paragraph.ALIGN_LEFT); // getDocument().add(p); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Paragraph p2 = new Paragraph("Date of Visit: " + sdf.format(appointment.getAppointmentDate()), getFont()); p2.setAlignment(Paragraph.ALIGN_RIGHT); // getDocument().add(p); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100f); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); PdfPCell cell1 = new PdfPCell(p); cell1.setBorder(PdfPCell.NO_BORDER); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); PdfPCell cell2 = new PdfPCell(p2); cell2.setHorizontalAlignment(Element.ALIGN_RIGHT); cell2.setBorder(PdfPCell.NO_BORDER); table.addCell(cell1); table.addCell(cell2); getDocument().add(table); table = new PdfPTable(3); table.setWidthPercentage(100f); table.getDefaultCell().setBorder(PdfPCell.NO_BORDER); cell1 = new PdfPCell(getParagraph("Signed Provider:" + ((signingProvider != null) ? signingProvider : ""))); cell1.setBorder(PdfPCell.BOTTOM); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); cell2 = new PdfPCell(getParagraph("RFR:" + this.appointment.getReason())); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); cell2.setBorder(PdfPCell.BOTTOM); PdfPCell cell3 = new PdfPCell(getParagraph("Ref:" + this.getRefName(this.demographic))); cell3.setHorizontalAlignment(Element.ALIGN_RIGHT); cell3.setBorder(PdfPCell.BOTTOM); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); getDocument().add(table); /* HeaderFooter footer = new HeaderFooter(new Phrase("-",font),new Phrase("-",font)); footer.setAlignment(HeaderFooter.ALIGN_CENTER); footer.setBorder(0); document.setFooter(footer); */ //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() - (font.getCalculatedLeading(LINESPACING)*5f)); cb.lineTo(document.right(), document.top() - (font.getCalculatedLeading(LINESPACING)*5f)); cb.stroke(); */ }
From source file:org.oscarehr.phr.web.PHRUserManagementAction.java
License:Open Source License
public ByteArrayOutputStream generateUserRegistrationLetter(String demographicNo, String username, String password) throws Exception { log.debug("Demographic " + demographicNo + " username " + username + " password " + password); DemographicDao demographicDao = (DemographicDao) SpringUtils.getBean("demographicDao"); Demographic demographic = demographicDao.getDemographic(demographicNo); final String PAGESIZE = "printPageSize"; Document document = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter writer = null;// ww w .j av a 2s .c o m try { writer = PdfWriter.getInstance(document, baosPDF); String title = "TITLE"; String template = "MyOscarLetterHead.pdf"; Properties printCfg = getCfgProp(); String[] cfgVal = null; StringBuilder tempName = null; // get the print prop values Properties props = new Properties(); props.setProperty("letterDate", UtilDateUtilities.getToday("yyyy-MM-dd")); props.setProperty("name", demographic.getFirstName() + " " + demographic.getLastName()); props.setProperty("dearname", demographic.getFirstName() + " " + demographic.getLastName()); props.setProperty("address", demographic.getAddress()); props.setProperty("city", demographic.getCity() + ", " + demographic.getProvince()); props.setProperty("postalCode", demographic.getPostal()); props.setProperty("credHeading", "MyOscar User Account Details"); props.setProperty("username", "Username: " + username); props.setProperty("password", "Password: " + password); //Temporary - the intro will change to be dynamic props.setProperty("intro", "We are pleased to provide you with a log in and password for your new MyOSCAR Personal Health Record. This account will allow you to connect electronically with our clinic. Please take a few minutes to review the accompanying literature for further information.We look forward to you benefiting from this service."); document.addTitle(title); document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); Rectangle pageSize = PageSize.LETTER; document.setPageSize(pageSize); document.open(); // create a reader for a certain document String propFilename = oscar.OscarProperties.getInstance().getProperty("pdfFORMDIR", "") + "/" + template; PdfReader reader = null; try { reader = new PdfReader(propFilename); log.debug("Found template at " + propFilename); } catch (Exception dex) { log.debug("change path to inside oscar from :" + propFilename); reader = new PdfReader("/oscar/form/prop/" + template); log.debug("Found template at /oscar/form/prop/" + template); } // retrieve the total number of pages int n = reader.getNumberOfPages(); // retrieve the size of the first page Rectangle pSize = reader.getPageSize(1); float width = pSize.getWidth(); float height = pSize.getHeight(); log.debug("Width :" + width + " Height: " + height); PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); int fontFlags = 0; document.newPage(); PdfImportedPage page1 = writer.getImportedPage(reader, 1); cb.addTemplate(page1, 1, 0, 0, 1, 0, 0); BaseFont bf; // = normFont; String encoding; cb.setRGBColorStroke(0, 0, 255); String[] fontType; for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) { tempName = new StringBuilder(e.nextElement().toString()); cfgVal = printCfg.getProperty(tempName.toString()).split(" *, *"); 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 fontFlags = Font.NORMAL; } else { fontFlags = Font.NORMAL; fontType = new String[] { cfgVal[4].trim() }; } 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; } bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED); // 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, props.getProperty(tempName.toString(), ""), font)); ct.go(); continue; } // draw line directly if (tempName.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())); // stroke the lines cb.stroke(); // write text directly } else if (tempName.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()) : props.getProperty(tempName.toString(), "")), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } else if (tempName.toString().equals("forms_promotext")) { if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) { 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)), OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), 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 ? ((props.getProperty(tempName.toString(), "").equals("") ? "" : cfgVal[6].trim())) : props.getProperty(tempName.toString(), "")), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } finally { if (document != null) document.close(); if (writer != null) writer.close(); } return baosPDF; }
From source file:org.oscarehr.web.reports.ocan.IndividualNeedRatingOverTimeReportGenerator.java
License:Open Source License
public void generateReport(OutputStream os) throws Exception { Document d = new Document(PageSize.A4.rotate()); d.setMargins(20, 20, 20, 20);//from www .ja v a 2 s. co m PdfWriter writer = PdfWriter.getInstance(d, os); writer.setStrictImageSequence(true); d.open(); //header Paragraph p = new Paragraph("Individual Need Rating Over Time", titleFont); p.setAlignment(Element.ALIGN_CENTER); d.add(p); d.add(Chunk.NEWLINE); //purpose Paragraph purpose = new Paragraph(); purpose.add(new Chunk("Purpose of Report:", boldText)); purpose.add(new Phrase( "The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.", normalText)); d.add(purpose); d.add(Chunk.NEWLINE); //report parameters PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(makeCell(createFieldNameAndValuePhrase("Consumer Name:", reportBean.getConsumerName()), Element.ALIGN_LEFT)); table.addCell(makeCell( createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(reportBean.getReportDate())), Element.ALIGN_RIGHT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", reportBean.getStaffName()), Element.ALIGN_LEFT)); table.addCell(""); d.add(table); d.add(Chunk.NEWLINE); int height = 260; if (reportBean.isShowUnmetNeeds()) { d.add(Image.getInstance(reportBean.getUnmetNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } if (reportBean.isShowMetNeeds()) { d.add(Image.getInstance(reportBean.getMetNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } if (reportBean.isShowNoNeeds()) { d.add(Image.getInstance(reportBean.getNoNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } if (reportBean.isShowUnknownNeeds()) { d.add(Image.getInstance(reportBean.getUnknownNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } d.close(); }
From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java
License:Open Source License
public void generateReport(OutputStream os) throws Exception { Document d = new Document(PageSize.A4.rotate()); d.setMargins(20, 20, 20, 20);/* w w w . jav a 2 s.c o m*/ PdfWriter writer = PdfWriter.getInstance(d, os); writer.setStrictImageSequence(true); d.open(); //header Paragraph p = new Paragraph("Needs Over Time (Consumer and Staff)", titleFont); p.setAlignment(Element.ALIGN_CENTER); d.add(p); d.add(Chunk.NEWLINE); //purpose Paragraph purpose = new Paragraph(); purpose.add(new Chunk("Purpose of Report:", boldText)); purpose.add(new Phrase( "The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.", normalText)); d.add(purpose); d.add(Chunk.NEWLINE); //report parameters PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell( makeCell(createFieldNameAndValuePhrase("Consumer Name:", getConsumerName()), Element.ALIGN_LEFT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(getReportDate())), Element.ALIGN_RIGHT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", getStaffName()), Element.ALIGN_LEFT)); table.addCell(""); d.add(table); d.add(Chunk.NEWLINE); //loop here...groups of 3 int loopNo = 1; List<OcanNeedRatingOverTimeSummaryOfNeedsBean> summaryBeanList = new ArrayList<OcanNeedRatingOverTimeSummaryOfNeedsBean>(); summaryBeanList.addAll(this.summaryOfNeedsBeanList); while (true) { if (summaryBeanList.size() == 0) { break; } List<OcanNeedRatingOverTimeSummaryOfNeedsBean> currentBeanList = new ArrayList<OcanNeedRatingOverTimeSummaryOfNeedsBean>(); for (int x = 0; x < 3; x++) { if (summaryBeanList.size() == 0) { break; } currentBeanList.add(summaryBeanList.remove(0)); } //summary of needs PdfPTable summaryOfNeedsTable = null; if (currentBeanList.size() == 1) { summaryOfNeedsTable = new PdfPTable(3); summaryOfNeedsTable.setWidthPercentage(100f - 52.8f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f }); } if (currentBeanList.size() == 2) { summaryOfNeedsTable = new PdfPTable(6); summaryOfNeedsTable.setWidthPercentage(100f - 26.4f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } if (currentBeanList.size() == 3) { summaryOfNeedsTable = new PdfPTable(9); summaryOfNeedsTable.setWidthPercentage(100f); summaryOfNeedsTable .setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } summaryOfNeedsTable.setHorizontalAlignment(Element.ALIGN_LEFT); summaryOfNeedsTable.setHeaderRows(3); addSummaryOfNeedsHeader(summaryOfNeedsTable, currentBeanList, loopNo); addSummaryOfNeedsRow(summaryOfNeedsTable, "Unmet Needs", "unmet", currentBeanList); addSummaryOfNeedsRow(summaryOfNeedsTable, "Met Needs", "met", currentBeanList); addSummaryOfNeedsRow(summaryOfNeedsTable, "No Needs", "no", currentBeanList); addSummaryOfNeedsRow(summaryOfNeedsTable, "Unknown Needs", "unknown", currentBeanList); d.add(summaryOfNeedsTable); d.add(Chunk.NEWLINE); if (summaryBeanList.size() == 0) { break; } loopNo++; } //BREAKDOWN OF SUMMARY OF NEEDS //loop here...groups of 3 loopNo = 1; List<OcanNeedRatingOverTimeNeedBreakdownBean> breakdownBeanList = new ArrayList<OcanNeedRatingOverTimeNeedBreakdownBean>(); breakdownBeanList.addAll(this.needBreakdownListByOCAN); OcanNeedRatingOverTimeNeedBreakdownBean lastBreakDownBean = null; while (true) { if (breakdownBeanList.size() == 0) { break; } List<OcanNeedRatingOverTimeNeedBreakdownBean> currentBeanList = new ArrayList<OcanNeedRatingOverTimeNeedBreakdownBean>(); for (int x = 0; x < 3; x++) { if (breakdownBeanList.size() == 0) { break; } currentBeanList.add(breakdownBeanList.remove(0)); } //summary of needs PdfPTable summaryOfNeedsTable = null; if (currentBeanList.size() == 1) { if (lastBreakDownBean == null) { summaryOfNeedsTable = new PdfPTable(3); summaryOfNeedsTable.setWidthPercentage(100f - 52.8f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f }); } else { summaryOfNeedsTable = new PdfPTable(4); summaryOfNeedsTable.setWidthPercentage(100f - 52.8f); summaryOfNeedsTable.setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f }); } } if (currentBeanList.size() == 2) { if (lastBreakDownBean == null) { summaryOfNeedsTable = new PdfPTable(6); summaryOfNeedsTable.setWidthPercentage(100f - 26.4f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } else { summaryOfNeedsTable = new PdfPTable(7); summaryOfNeedsTable.setWidthPercentage(100f - 26.4f); summaryOfNeedsTable .setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } } if (currentBeanList.size() == 3) { if (lastBreakDownBean == null) { summaryOfNeedsTable = new PdfPTable(9); summaryOfNeedsTable.setWidthPercentage(100f); summaryOfNeedsTable.setWidths( new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } else { summaryOfNeedsTable = new PdfPTable(10); summaryOfNeedsTable.setWidthPercentage(100f); summaryOfNeedsTable.setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } } summaryOfNeedsTable.setHorizontalAlignment(Element.ALIGN_LEFT); addSummaryOfNeedsDomainHeader(summaryOfNeedsTable, currentBeanList, loopNo); for (int x = 0; x < domains.size(); x++) { addSummaryOfNeedsDomainRow(summaryOfNeedsTable, x, getDomains(), currentBeanList, lastBreakDownBean); } d.add(summaryOfNeedsTable); d.add(Chunk.NEWLINE); if (breakdownBeanList.size() == 0) { break; } if (currentBeanList.size() == 3) { lastBreakDownBean = currentBeanList.get(2); } loopNo++; } JFreeChart chart = generateNeedsOverTimeChart(); BufferedImage image = chart.createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, 350); Image image2 = Image.getInstance(image, null); d.add(image2); d.close(); }
From source file:org.oscarehr.web.reports.ocan.SummaryOfActionsAndCommentsReportGenerator.java
License:Open Source License
public void generateReport(OutputStream os) throws Exception { Document d = new Document(PageSize.A4.rotate()); d.setMargins(20, 20, 20, 20);// www. j av a2 s. c om PdfWriter writer = PdfWriter.getInstance(d, os); writer.setStrictImageSequence(true); d.open(); //header Paragraph p = new Paragraph("Summary of Actions and Comments", titleFont); p.setAlignment(Element.ALIGN_CENTER); d.add(p); d.add(Chunk.NEWLINE); //purpose Paragraph purpose = new Paragraph(); purpose.add(new Chunk("Purpose of Report:", boldText)); purpose.add(new Phrase( "This report displays a summary of Actions and Comments (both for the Consumer and the Staff) that were recorded in the selected OCANs for an individual Consumer. The report lists all the Actions and Comments associated to OCANs and Domains that were chosen by the Staff to be displayed. The Actions also list who is responsible for the Action and the Review Date for the Action. The Domains are categorized by need rating within within the current OCAN as well as displaying the need ratings from the previous OCANs. In the case of different need ratings by the Consumer and the Mental Health Worker, the higher need rating determines the category. The need ratings from highest to lowest are Unmet Needs, Met Needs, No Needs, and Unknown. The need rating given by the Consumer and the Staff are also displayed next to the Comments for each OCAN. This information can be passed along to other organizations if requested.", normalText)); d.add(purpose); d.add(Chunk.NEWLINE); //report parameters PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell( makeCell(createFieldNameAndValuePhrase("Consumer Name:", getConsumerName()), Element.ALIGN_LEFT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(getReportDate())), Element.ALIGN_RIGHT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", getStaffName()), Element.ALIGN_LEFT)); table.addCell(""); d.add(table); d.add(Chunk.NEWLINE); if (reportBean == null) { d.close(); return; } List<SummaryOfActionsAndCommentsDomainBean> unMetCategory = reportBean.getUnmetNeeds(); List<SummaryOfActionsAndCommentsDomainBean> metCategory = reportBean.getMetNeeds(); List<SummaryOfActionsAndCommentsDomainBean> noCategory = reportBean.getNoNeeds(); List<SummaryOfActionsAndCommentsDomainBean> unknownCategory = reportBean.getUnknown(); PdfPTable unmetTable = null; if (unMetCategory.size() > 0) { unmetTable = createNeedHeader("Unmet Needs"); } for (SummaryOfActionsAndCommentsDomainBean domain : unMetCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(unmetTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(unmetTable, ocanBean); } } } if (unmetTable != null) { d.add(unmetTable); d.add(Chunk.NEWLINE); } PdfPTable metTable = null; if (metCategory.size() > 0) { metTable = createNeedHeader("Met Needs"); } for (SummaryOfActionsAndCommentsDomainBean domain : metCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(metTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(metTable, ocanBean); } } } if (metTable != null) { d.add(metTable); d.add(Chunk.NEWLINE); } PdfPTable noTable = null; if (noCategory.size() > 0) { noTable = createNeedHeader("No Needs"); } for (SummaryOfActionsAndCommentsDomainBean domain : noCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(noTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(noTable, ocanBean); } } } if (noTable != null) { d.add(noTable); d.add(Chunk.NEWLINE); } PdfPTable unknownTable = null; if (unknownCategory.size() > 0) { unknownTable = createNeedHeader("Unknown"); } for (SummaryOfActionsAndCommentsDomainBean domain : unknownCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(unknownTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(unknownTable, ocanBean); } } } if (unknownTable != null) { d.add(unknownTable); } d.close(); }