List of usage examples for com.lowagie.text Phrase getLeading
public float getLeading()
From source file:org.oscarehr.casemgmt.service.CaseManagementPrintPdf.java
License:Open Source License
public void printDocHeaderFooter() throws IOException, DocumentException { //Create the document we are going to write to document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); document.setPageSize(PageSize.LETTER); document.open();//from w w w. ja va2 s . c om //Create the font we are going to print to bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.NOT_EMBEDDED); font = new Font(bf, FONTSIZE, Font.NORMAL); String title = "", gender = "", dob = "", age = "", mrp = ""; if (this.demoDtl != null) { //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) demoDtl.get("demoName") + "\n"; gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) demoDtl.get("demoSex") + "\n"; dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) demoDtl.get("demoDOB") + "\n"; age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) demoDtl.get("demoAge") + "\n"; mrp = propResource.getString("oscarEncounter.pdfPrint.mrp") + " " + (String) demoDtl.get("mrp") + "\n"; } else { //set up document title and header ResourceBundle propResource = ResourceBundle.getBundle("oscarResources"); title = propResource.getString("oscarEncounter.pdfPrint.title") + " " + (String) request.getAttribute("demoName") + "\n"; gender = propResource.getString("oscarEncounter.pdfPrint.gender") + " " + (String) request.getAttribute("demoSex") + "\n"; dob = propResource.getString("oscarEncounter.pdfPrint.dob") + " " + (String) request.getAttribute("demoDOB") + "\n"; age = propResource.getString("oscarEncounter.pdfPrint.age") + " " + (String) request.getAttribute("demoAge") + "\n"; 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(), "Fax: " + clinicData.getClinicFax() }; //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); ColumnText ct = new ColumnText(cb); Paragraph p = new Paragraph(); p.setAlignment(Paragraph.ALIGN_LEFT); Phrase phrase = new Phrase(); Phrase dummy = new Phrase(); for (int idx = 0; idx < clinic.length; ++idx) { phrase.add(clinic[idx] + "\n"); dummy.add("\n"); upperYcoord -= phrase.getLeading(); } dummy.add("\n"); ct.setSimpleColumn(document.left(), upperYcoord, document.right() / 2f, document.top()); ct.addElement(phrase); ct.go(); p.add(dummy); document.add(p); //add patient info phrase = new Phrase(); p = new Paragraph(); p.setAlignment(Paragraph.ALIGN_RIGHT); for (int idx = 0; idx < info.length; ++idx) { phrase.add(info[idx]); } ct.setSimpleColumn(document.right() / 2f, upperYcoord, document.right(), document.top()); p.add(phrase); ct.addElement(p); ct.go(); cb.moveTo(document.left(), upperYcoord); cb.lineTo(document.right(), upperYcoord); cb.stroke(); upperYcoord -= phrase.getLeading(); if (Boolean.parseBoolean(OscarProperties.getInstance().getProperty("ICFHT_CONVERT_TO_PDF", "false"))) { printPersonalInfo(); } }