List of usage examples for com.lowagie.text.pdf PdfPCell setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception { if (text == null) return;/*from ww w.ja va2 s. co m*/ if (text.indexOf("<span") >= 0) text = text.replaceAll("</span>", "").replaceAll("<span .*>", ""); Font font = PdfFont.getFont(bold); BaseFont bf = font.getBaseFont(); float width = bf.getWidthPoint(text, font.getSize()); PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width); template.beginText(); template.setColorFill(Color.BLACK); template.setFontAndSize(bf, font.getSize()); template.setTextMatrix(0, 2); template.showText(text); template.endText(); template.setWidth(width); template.setHeight(font.getSize() + 2); //make an Image object from the template Image img = Image.getInstance(template); img.setRotationDegrees(270); //embed the image in a Chunk Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); } else { cell.getPhrase().add(ck); } }
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void printLegend() throws Exception { iPdfTable = new PdfPTable(2); iPdfTable.setWidths(new float[] { 10f, 200f }); iPdfTable.getDefaultCell().setPadding(3); iPdfTable.getDefaultCell().setBorderWidth(1); iPdfTable.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.setSplitRows(false);//from w w w . j a v a2s.co m iPdfTable.setSpacingBefore(10); iPdfTable.setKeepTogether(true); if (iTable.getBgMode() != TimetableGridModel.sBgModeNone) { PdfPCell c = createCellNoBorder(); c.setColspan(2); addText(c, "Assigned classes:"); c.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.addCell(c); } if (iTable.getBgMode() == TimetableGridModel.sBgModeTimePref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Preferred time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No time preference"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged time"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited time"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeRoomPref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "Strongly preferred room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Preferred room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No room preference"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited room"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeStudentConf) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = TimetableGridCell.conflicts2color(nrConflicts); addLegendRow(color, "" + nrConflicts + " " + (nrConflicts == 15 ? "or more " : "") + "student conflicts"); } } else if (iTable.getBgMode() == TimetableGridModel.sBgModeInstructorBtbPref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No instructor back-to-back preference (distance=0)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged back-to-back (0<distance<=5)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged back-to-back (5<distance<=20)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Prohibited back-to-back (20<distance)"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeDistributionConstPref) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No violated constraint(distance=0)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Discouraged/preferred constraint violated"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Strongly discouraged/preferred constraint violated"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Required/prohibited constraint violated"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModePerturbations) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "No change"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No initial assignment"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Room changed"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Time changed"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Both time and room changed"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModePerturbationPenalty) { for (int nrConflicts = 0; nrConflicts <= 15; nrConflicts++) { String color = TimetableGridCell.conflicts2color(nrConflicts); addLegendRow(color, "" + (nrConflicts == 0 ? "Zero perturbation penalty" : nrConflicts == 15 ? "Perturbation penalty above 15" : "Perturbation penalty below or equal to " + nrConflicts) + ""); } } else if (iTable.getBgMode() == TimetableGridModel.sBgModeHardConflicts) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Required time and room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyPreferred), "Can be moved in room with no hard conflict"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sPreferred), "Can be moved in room (but there is a hard conflict), can be moved in time with no conflict"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "Can be moved in room (but there is a hard conflict)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Can be moved in time with no hard conflict, cannot be moved in room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Can be moved in time (but there is a hard conflict), cannot be moved in room"); } else if (iTable.getBgMode() == TimetableGridModel.sBgModeDepartmentalBalancing) { for (int nrConflicts = 0; nrConflicts <= 3; nrConflicts++) { String color = TimetableGridCell.conflicts2colorFast(nrConflicts); addLegendRow(color, "" + (nrConflicts == 0 ? "Zero penalty" : nrConflicts == 3 ? "Penalty equal or above 3" : "Penalty equal to " + nrConflicts) + ""); } } else if (iTable.getBgMode() == TimetableGridModel.sBgModeTooBigRooms) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sRequired), "Assigned room is smaller than room limit of a class"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "Assigned room is not more than 25% bigger than the smallest avaialable room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Assigned room is not more than 50% bigger than the smallest avaialable room"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Assigned room is more than 50% bigger than the smallest avaialable room"); } PdfPCell c = createCellNoBorder(); c.setColspan(2); addText(c, "Free times:"); c.setHorizontalAlignment(Element.ALIGN_LEFT); iPdfTable.addCell(c); addLegendRow(TimetableGridCell.sBgColorNotAvailable, "Time not available"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sNeutral), "No preference"); if (iTable.getShowUselessTimes()) { addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sDiscouraged), "Standard (MWF or TTh) time pattern is broken (time cannot be used for MW, WF, MF or TTh class)"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sStronglyDiscouraged), "Useless half-hour"); addLegendRow(TimetableGridCell.pref2color(PreferenceLevel.sProhibited), "Useless half-hour and broken standard time pattern"); } if (iTable.isDispModePerWeekVertical()) iDocument.newPage(); iDocument.add(iPdfTable); }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
/** * Creates and adds the table at the top of the document * which contains the consultation request. *//* w w w. j ava2 s. c o m*/ private void createConsultationRequest() throws DocumentException { float[] tableWidths = { 1f, 1f }; PdfPTable table = new PdfPTable(1); PdfPCell cell; PdfPTable border, border2, border1; table.setWidthPercentage(95); // Creating a border for the entire request. border = new PdfPTable(1); addToTable(table, border, true); if (props.getProperty("faxLogoInConsultation") != null) { // Creating container for logo and clinic information table. border1 = new PdfPTable(tableWidths); addTable(border, border1); // Adding fax logo PdfPTable infoTable = createLogoHeader(); addToTable(border1, infoTable, false); // Adding clinic information to the border. infoTable = createClinicInfoHeader(); addToTable(border1, infoTable, false); } else { // Adding clinic information to the border. PdfPTable infoTable = createClinicInfoHeader(); addTable(border, infoTable); } // Add reply info PdfPTable infoTable = createReplyHeader(); addTable(border, infoTable); // Creating container for specialist and patient table. border2 = new PdfPTable(tableWidths); addTable(border, border2); // Adding specialist info to container. infoTable = createSpecialistTable(); addToTable(border2, infoTable, true); // Adding patient info to main table. infoTable = createPatientTable(); addToTable(border2, infoTable, true); // Creating a table with details for the consultation request. infoTable = createConsultDetailTable(); // Adding promotional information if appropriate. if (props.getProperty("FORMS_PROMOTEXT") != null) { cell = new PdfPCell(new Phrase(props.getProperty(""), font)); cell.setBorder(0); infoTable.addCell(cell); cell.setPhrase(new Phrase(props.getProperty("FORMS_PROMOTEXT"), font)); cell.setVerticalAlignment(Element.ALIGN_BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.addCell(cell); } // Adding details and promotional information. addTable(border, infoTable); document.add(table); }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
private PdfPTable createReplyHeader() { PdfPCell cell; PdfPTable infoTable = new PdfPTable(1); cell = new PdfPCell(new Phrase("", headerFont)); cell.setBorder(0);//w w w . j a v a2 s .c o m cell.setPaddingLeft(25); infoTable.addCell(cell); cell.setPhrase(new Phrase(getResource("msgConsReq"), bigBoldFont)); cell.setPadding(0); cell.setBorder(0); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); infoTable.addCell(cell); if (reqFrm.pwb.equals("1")) { cell.setPhrase(new Phrase(getResource("msgPleaseReplyPatient"), boldFont)); } else if (org.oscarehr.common.IsPropertiesOn.isMultisitesEnable()) { cell.setPhrase(new Phrase("", boldFont)); } else { cell.setPhrase(new Phrase(String.format("%s %s %s", getResource("msgPleaseReplyPart1"), clinic.getClinicName(), getResource("msgPleaseReplyPart2")), boldFont)); } infoTable.addCell(cell); // The last cell in the table is extended to the maximum available height; // inserting a blank cell here prevents the last border used to underline text from // being displaced to the bottom of this table. cell.setPhrase(new Phrase(" ", font)); cell.setBorder(0); cell.setColspan(2); infoTable.addCell(cell); return infoTable; }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
/** * Creates the table containing additional information * about the reason for the consultation request. * @return the table produced/*from w ww. jav a 2s . c o m*/ */ private PdfPTable createConsultDetailTable() { PdfPTable infoTable; PdfPCell cell; infoTable = new PdfPTable(1); cell = new PdfPCell(); infoTable.addCell(setInfoCell2(cell, getResource("msgReason"))); infoTable.addCell(setDataCell2(cell, reqFrm.reasonForConsultation)); if (getlen(reqFrm.clinicalInformation) > 1) { infoTable.addCell(setInfoCell(cell, getResource("msgClinicalInfom"))); infoTable.addCell(setDataCell(cell, divy(reqFrm.clinicalInformation))); } if (getlen(reqFrm.concurrentProblems) > 1) { if (props.getProperty("significantConcurrentProblemsTitle", "").length() > 1) { infoTable.addCell(setInfoCell(cell, props.getProperty("significantConcurrentProblemsTitle", ""))); } else { infoTable.addCell(setInfoCell(cell, getResource("msgSigProb"))); } infoTable.addCell(setDataCell(cell, divy(reqFrm.concurrentProblems))); } if (getlen(reqFrm.currentMedications) > 1) { if (props.getProperty("currentMedicationsTitle", "").length() > 1) { infoTable.addCell(setInfoCell(cell, props.getProperty("currentMedicationsTitle", ""))); } else { infoTable.addCell(setInfoCell(cell, getResource("msgCurrMed"))); } infoTable.addCell(setDataCell(cell, divy(reqFrm.currentMedications))); } if (getlen(reqFrm.allergies) > 1) { infoTable.addCell(setInfoCell(cell, getResource("msgAllergies"))); infoTable.addCell(setDataCell(cell, divy(reqFrm.allergies))); } if (getlen(reqFrm.ocularExamination) > 1) { infoTable.addCell(setInfoCell(cell, getResource("msgOcularExamination"))); infoTable.addCell(setDataCell(cell, divy(reqFrm.ocularExamination))); } ProviderDao proDAO = (ProviderDao) SpringUtils.getBean("providerDao"); org.oscarehr.common.model.Provider pro = proDAO.getProvider(reqFrm.providerNo); String billingNo = pro.getBillingNo(); DemographicDao demoDAO = (DemographicDao) SpringUtils.getBean("demographicDao"); Demographic demo = demoDAO.getDemographic(reqFrm.demoNo); pro = proDAO.getProvider(demo.getProviderNo()); String famDocBillingNo = pro.getBillingNo(); //infoTable.addCell(setFooterCell(cell, getResource("msgAssociated2"), reqFrm.getProviderName(reqFrm.providerNo) + ((getlen(billingNo) > 0) ? " (" + billingNo + ")" : ""))); //infoTable.addCell(setFooterCell(cell, getResource("msgFamilyDoc2"), reqFrm.getFamilyDoctor() + ((getlen(famDocBillingNo) > 0) ? " (" + famDocBillingNo + ")" : ""))); if (props.getProperty("CONSULTATION_SIGNATURE_LINE1") != null) { cell.setPadding(0); cell.setBorder(0); cell.setPhrase(new Phrase(props.getProperty("CONSULTATION_SIGNATURE_LINE1"))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); if (props.getProperty("CONSULTATION_SIGNATURE_LINE2") != null) { cell.setPadding(0); cell.setBorder(0); cell.setPhrase(new Phrase(props.getProperty("CONSULTATION_SIGNATURE_LINE2"))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); } if (props.getProperty("CONSULTATION_SIGNATURE_LINE3") != null) { cell.setPadding(0); cell.setBorder(0); cell.setPhrase(new Phrase(props.getProperty("CONSULTATION_SIGNATURE_LINE3"))); cell.setHorizontalAlignment(Element.ALIGN_LEFT); infoTable.addCell(cell); } } else { infoTable.addCell(setFooterCell(cell, getResource("msgAssociated2"), reqFrm.getFamilyDoctor() + ((getlen(famDocBillingNo) > 0) ? " (" + famDocBillingNo + ")" : ""))); infoTable.addCell( setFooterCell(cell, getResource("msgCreatedBy"), reqFrm.getProviderName(reqFrm.providerNo) + ((getlen(billingNo) > 0) ? " (" + billingNo + ")" : ""))); } if (getlen(reqFrm.signatureImg) > 0) { addSignature(infoTable); } return infoTable; }
From source file:oscar.oscarEncounter.oscarConsultationRequest.pageUtil.ConsultationPDFCreator.java
License:Open Source License
private void addSignature(PdfPTable infoTable) { float[] tableWidths; PdfPCell cell; tableWidths = new float[] { 0.55f, 2.75f }; PdfPTable table = new PdfPTable(tableWidths); cell = new PdfPCell(new Phrase(getResource("msgSignature") + ":", infoFont)); cell.setBorder(0);/*from w w w .j a va2s . co m*/ cell.setHorizontalAlignment(PdfPCell.ALIGN_BOTTOM); table.addCell(cell); try { DigitalSignatureDao digitalSignatureDao = (DigitalSignatureDao) SpringUtils .getBean("digitalSignatureDao"); DigitalSignature digitalSignature = digitalSignatureDao.find(Integer.parseInt(reqFrm.signatureImg)); if (digitalSignature != null) { Image image = Image.getInstance(digitalSignature.getSignatureImage()); image.scalePercent(80f); image.setBorder(0); cell = new PdfPCell(image); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(table); cell.setBorder(0); cell.setPadding(0); cell.setColspan(1); infoTable.addCell(cell); return; } } catch (Exception e) { logger.error("Unexpected error.", e); } }
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();/* w w w .j av a 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);/* w w w. j a v a2 s .c om*/ 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:permit.InvoicePdf.java
License:Open Source License
/** * handles the letter header//from ww w . java 2 s . c o m */ 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; }
From source file:permit.InvoicePdf.java
License:Open Source License
void writePages(HttpServletResponse res, Invoice invoice) { //// w w w . jav a 2s . com // paper size legal (A4) 8.5 x 11 // page 1-inch = 72 points // String fileName = "row_invoice_" + invoice.getInvoice_num() + ".pdf"; Rectangle pageSize = new Rectangle(612, 792); // 8.5" X 11" Document document = new Document(pageSize, 36, 36, 18, 18); ServletOutputStream out = null; Font fnt = new Font(Font.TIMES_ROMAN, 10, Font.NORMAL); Font fntb = new Font(Font.TIMES_ROMAN, 10, Font.BOLD); Font fnts = new Font(Font.TIMES_ROMAN, 8, Font.NORMAL); Font fntbs = new Font(Font.TIMES_ROMAN, 8, Font.BOLD); String spacer = " "; PdfPTable header = getHeader(); Company company = invoice.getCompany(); Contact contact = null; if (invoice.hasContact()) { contact = invoice.getContact(); } List<Page> pages = invoice.getPages(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); String str = ""; document.open(); document.add(header); // // title float[] width = { 100f }; // one cell PdfPTable table = new PdfPTable(width); table.setWidthPercentage(100.0f); PdfPCell cell = new PdfPCell(new Phrase("INVOICE", fntb)); // cell.setBorder(Rectangle.BOTTOM); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); document.add(table); // // we need these later Paragraph pp = new Paragraph(); Chunk ch = new Chunk(" ", fntb); Phrase phrase = new Phrase(); // float[] widths = { 35f, 30f, 35f }; // percentages table = new PdfPTable(widths); table.setWidthPercentage(100.0f); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); // // first row float[] widthOne = { 100f }; PdfPTable leftTable = new PdfPTable(widthOne); leftTable.setWidthPercentage(35.0f); leftTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // if (company != null) { ch = new Chunk("Company\n", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(company.getName() + "\n", fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } if (contact != null) { phrase = new Phrase(); ch = new Chunk(contact.getFullName(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); phrase = new Phrase(); ch = new Chunk(contact.getAddress(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); ch = new Chunk(contact.getCityStateZip(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); leftTable.addCell(cell); } table.addCell(leftTable); // // middle cell // cell = new PdfPCell(new Phrase(spacer, fnt)); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); // float[] widths2 = { 50f, 50f }; // percentages PdfPTable rightTable = new PdfPTable(widths2); rightTable.setWidthPercentage(35.0f); rightTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); // ch = new Chunk("Invoice No.", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getInvoice_num(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Status", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getStatus(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("Invoice Date", fntb); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk(invoice.getDate(), fnt); phrase = new Phrase(); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("From ", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(invoice.getStart_date(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); // ch = new Chunk("To ", fntb); phrase = new Phrase(); phrase.add(ch); ch = new Chunk(invoice.getEnd_date(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setBorder(Rectangle.NO_BORDER); rightTable.addCell(cell); table.addCell(rightTable); // // document.add(table); // phrase = new Phrase(new Chunk(spacer, fnt)); document.add(phrase); // int jj = 0; if (pages != null) { for (Page page : pages) { jj++; // float[] widthOne = {100f}; PdfPTable borderTable = new PdfPTable(widthOne); borderTable.setWidthPercentage(100.0f); borderTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); float[] widthTwo = { 50f, 50f }; PdfPTable titleTable = new PdfPTable(widthTwo); titleTable.setWidthPercentage(75.0f); titleTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); phrase = new Phrase("Invoice No. ", fntb); ch = new Chunk(invoice.getInvoice_num(), fnt); phrase.add(ch); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_LEFT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // phrase = new Phrase(page.getPage_num(), fnt); cell = new PdfPCell(phrase); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setBorder(Rectangle.NO_BORDER); titleTable.addCell(cell); // borderTable.addCell(titleTable); float[] width4 = { 25f, 40f, 25f, 10f }; PdfPTable contTable = new PdfPTable(width4); cell = new PdfPCell(new Phrase("Excavation Permit Number", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Project", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Date Issued", fntb)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("Permit Fee", fntb)); contTable.addCell(cell); List<Permit> permits = page.getPermits(); if (permits != null) { for (Permit permit : permits) { cell = new PdfPCell(new Phrase(permit.getPermit_num(), fnt)); contTable.addCell(cell); phrase = new Phrase(permit.getProject() + "\n", fnt); List<Excavation> cuts = permit.getExcavations(); if (cuts != null) { for (Excavation one : cuts) { ch = new Chunk(one.getAddress() + " (" + one.getCut_type() + ")", fnt); phrase.add(ch); } } cell = new PdfPCell(phrase); contTable.addCell(cell); cell = new PdfPCell(new Phrase(permit.getDate(), fnt)); contTable.addCell(cell); cell = new PdfPCell(new Phrase("$" + permit.getFee(), fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); contTable.addCell(cell); cell = new PdfPCell(new Phrase(spacer, fnt)); // // space line cell.setColspan(4); contTable.addCell(cell); } } if (page.getNeededLines() > 0) { // first page for (int j = 0; j < page.getNeededLines(); j++) { cell = new PdfPCell(new Phrase(spacer, fnt)); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); contTable.addCell(cell); } } if (jj == pages.size()) { cell = new PdfPCell(new Phrase("Total Invoice Amount\n" + invoice.getTotal(), fntb)); cell.setHorizontalAlignment(Rectangle.ALIGN_RIGHT); cell.setColspan(4); contTable.addCell(cell); } borderTable.addCell(contTable); cell = new PdfPCell(new Phrase( "Payment due upon receipt. Please Make check payable to 'City of Bloomington'. Thank You.", fnt)); cell.setHorizontalAlignment(Rectangle.ALIGN_CENTER); cell.setBorder(Rectangle.NO_BORDER); borderTable.addCell(cell); borderTable.addCell(titleTable); // invoice and date document.add(borderTable); if (jj < pages.size()) { document.newPage(); } } } // document.close(); writer.close(); res.setHeader("Expires", "0"); res.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); // // if you want for users to download, uncomment the following line // // res.setHeader("Content-Disposition","attachment; filename="+fileName); res.setHeader("Pragma", "public"); // // setting the content type res.setContentType("application/pdf"); // // the contentlength is needed for MSIE!!! res.setContentLength(baos.size()); // out = res.getOutputStream(); if (out != null) { baos.writeTo(out); } } catch (Exception ex) { logger.error(ex); } }