List of usage examples for com.lowagie.text.pdf ColumnText setSimpleColumn
public void setSimpleColumn(float llx, float lly, float urx, float ury, float leading, int alignment)
From source file:nl.dykema.jxmlnote.report.pdf.PdfReport.java
License:Open Source License
private float getHeight(ReportElement el, ReportElement last) throws ReportException { try {/* w ww .j a v a2 s . co m*/ ColumnText ct = new ColumnText(_writer.getDirectContent()); if (el instanceof PdfParagraph) { PdfParagraph par = ((PdfParagraph) el); if ((el != last) || (el == last && par.hasImage())) { int status = ColumnText.START_COLUMN; Rectangle m = getMargins();//System.out.println(m); Rectangle p = getPageRect();//System.out.println(p); float leading = par.getLeading(); int align = par.getAlignment(); ct.setSimpleColumn(m.left(), m.bottom(), p.width() - m.right(), p.height() - m.top(), leading, align); //,Element.ALIGN_JUSTIFIED); ct.addElement(par); float pos = ct.getYLine(); status = ct.go(true); float npos = ct.getYLine(); return pos - npos; } else { float lineheight = par.getFont().getSize() * par.getMultipliedLeading(); float threelines = 3 * lineheight; //System.out.println("par:"+par+";lineheight:"+lineheight+";threelines:"+threelines); return threelines; } } else if (el instanceof PdfTable) { PdfTable tbl = ((PdfTable) el); int status = ColumnText.START_COLUMN; Rectangle m = getMargins();//System.out.println(m); Rectangle p = getPageRect();//System.out.println(p); float leading = 0.0f; //tbl.getLeading(); int align = tbl.getHorizontalAlignment(); ct.setSimpleColumn(m.left(), m.bottom(), p.width() - m.right(), p.height() - m.top(), leading, align); //,Element.ALIGN_JUSTIFIED); ct.addElement(tbl); float pos = ct.getYLine(); status = ct.go(true); float npos = ct.getYLine(); return pos - npos; } else { throw new ReportException("Unknown ReportElement:" + el.getClass().getName()); } } catch (Exception e) { throw new ReportException(e); } }
From source file:org.areasy.common.doclet.document.Index.java
License:Open Source License
/** * Creates a simple alphabetical index of all * classes and members of the API./* w ww . j ava 2 s . c o m*/ * * @throws Exception If the Index could not be created. */ public void create() throws Exception { if (!DefaultConfiguration.getBooleanConfigValue(ARG_CREATE_INDEX, false)) { log.trace("Index creation disabled."); return; } log.trace("Start creating Index..."); State.setCurrentHeaderType(HEADER_INDEX); State.increasePackageChapter(); // Name of the package (large font) pdfDocument.newPage(); // Create "Index" bookmark String label = DefaultConfiguration.getString(ARG_LB_OUTLINE_INDEX, LB_INDEX); String dest = "INDEX:"; Bookmarks.addRootBookmark(label, dest); Chunk indexChunk = new Chunk(label, Fonts.getFont(TEXT_FONT, BOLD, 30)); indexChunk.setLocalDestination(dest); Paragraph indexParagraph = new Paragraph((float) 30.0, indexChunk); pdfDocument.add(indexParagraph); // we grab the ContentByte and do some stuff with it PdfContentByte cb = pdfWriter.getDirectContent(); ColumnText ct = new ColumnText(cb); ct.setLeading((float) 9.0); float[] right = { 70, 320 }; float[] left = { 300, 550 }; // fill index columns with text String letter = ""; Set keys = memberList.keySet(); // keys must be sorted case unsensitive ArrayList sortedKeys = new ArrayList(keys.size()); // Build sorted list of all entries Iterator keysIterator = keys.iterator(); while (keysIterator.hasNext()) { sortedKeys.add(keysIterator.next()); } Collections.sort(sortedKeys, this); Iterator realNames = sortedKeys.iterator(); while (realNames.hasNext()) { String memberName = (String) realNames.next(); String currentLetter = memberName.substring(0, 1).toUpperCase(); log.trace("Create index entry for " + memberName); // Check if next letter in alphabet is reached if (currentLetter.equalsIgnoreCase(letter) == false) { // If yes, switch to new letter and print it letter = currentLetter.toUpperCase(); Paragraph lphrase = new Paragraph((float) 13.0); lphrase.add(new Chunk("\n\n" + letter + "\n", Fonts.getFont(TEXT_FONT, 12))); ct.addText(lphrase); } // Print member name Paragraph phrase = new Paragraph((float) 10.0); phrase.add(new Chunk("\n" + memberName + " ", Fonts.getFont(TEXT_FONT, 9))); Iterator sortedPages = getSortedPageNumbers(memberName); boolean firstNo = true; while (sortedPages.hasNext()) { Integer pageNo = (Integer) sortedPages.next(); // Always add 1 to the stored value, because the pages were // counted beginning with 0 internally, but their visible // numbering starts with 1 String pageNumberText = String.valueOf(pageNo.intValue() + 1); if (!firstNo) { phrase.add(new Chunk(", ", Fonts.getFont(TEXT_FONT, 9))); } phrase.add(new Chunk(pageNumberText, Fonts.getFont(TEXT_FONT, 9))); firstNo = false; } ct.addText(phrase); } // Now print index by printing columns into document int status = 0; int column = 0; while ((status & ColumnText.NO_MORE_TEXT) == 0) { ct.setSimpleColumn(right[column], 60, left[column], 790, 16, Element.ALIGN_LEFT); status = ct.go(); if ((status & ColumnText.NO_MORE_COLUMN) != 0) { column++; if (column > 1) { pdfDocument.newPage(); column = 0; } } } log.trace("Index created."); }
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;//from w ww . ja va2 s.co 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.tellervo.desktop.print.CompleteBoxLabel.java
License:Open Source License
public void generateBoxLabel(OutputStream output) { try {//from ww w. jav a 2 s . c om PdfWriter writer = PdfWriter.getInstance(document, output); document.setPageSize(PageSize.LETTER); document.open(); cb = writer.getDirectContent(); // Set basic metadata document.addAuthor("Peter Brewer"); document.addSubject("Box Label"); for (WSIBox b : this.boxlist) { // Title Left ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.top(15) - 210, 368, document.top(15), 20, Element.ALIGN_LEFT); ct.addText(getTitlePDF(b)); ct.go(); // Barcode ColumnText ct2 = new ColumnText(cb); ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20, Element.ALIGN_RIGHT); ct2.addElement(getBarCode(b)); ct2.go(); // Timestamp ColumnText ct3 = new ColumnText(cb); ct3.setSimpleColumn(document.left(), document.top(15) - 223, 350, document.top(15) - 60, 20, Element.ALIGN_LEFT); ct3.setLeading(0, 1.2f); ct3.addText(getTimestampPDF(b)); ct3.go(); // Pad text document.add(new Paragraph(" ")); Paragraph p2 = new Paragraph(); p2.setSpacingBefore(70); p2.setSpacingAfter(10); p2.add(new Chunk(" ", bodyFontLarge)); document.add(new Paragraph(p2)); // Ring samples table addTable(b); document.add(getParagraphSpace()); document.add(getComments(b)); document.newPage(); } } catch (DocumentException de) { System.err.println(de.getMessage()); } // Close the document document.close(); }
From source file:org.tellervo.desktop.print.ProSheet.java
License:Open Source License
private void generateProSheet(OutputStream output) { Paragraph spacingPara = new Paragraph(); spacingPara.setSpacingBefore(10);// w w w.ja v a 2 s . com spacingPara.add(new Chunk(" ", bodyFont)); try { PdfWriter writer = PdfWriter.getInstance(document, output); document.setPageSize(PageSize.LETTER); // Set basic metadata document.addAuthor("Peter Brewer"); document.addSubject("Corina Provenience Sheet for " + o.getTitle()); HeaderFooter footer = new HeaderFooter(new Phrase(""), new Phrase("")); footer.setAlignment(Element.ALIGN_RIGHT); footer.setBorder(0); document.setFooter(footer); HeaderFooter header = new HeaderFooter(new Phrase(o.getLabCode() + " - " + o.getTitle(), bodyFont), false); header.setAlignment(Element.ALIGN_RIGHT); header.setBorder(0); document.setHeader(header); document.open(); cb = writer.getDirectContent(); // Title Left ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.top() - 193, document.right(), document.top() - 20, 20, Element.ALIGN_LEFT); ct.addText(getTitlePDF()); ct.go(); // Timestamp ColumnText ct3 = new ColumnText(cb); ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20, Element.ALIGN_LEFT); ct3.setLeading(0, 1.2f); ct3.addText(getTimestampPDF()); ct3.go(); // Pad text document.add(spacingPara); document.add(getObjectDescription()); document.add(getObjectComments()); document.add(spacingPara); getElementTable(); } catch (DocumentException de) { System.err.println(de.getMessage()); } // Close the document document.close(); }
From source file:org.tellervo.desktop.print.SeriesReport.java
License:Open Source License
private void generateSeriesReport(OutputStream output) { displayUnits = NormalTridasUnit//from w w w. jav a 2s . c o m .valueOf(App.prefs.getPref(PrefKey.DISPLAY_UNITS, NormalTridasUnit.MICROMETRES.name().toString())); try { PdfWriter writer = PdfWriter.getInstance(document, output); document.setPageSize(PageSize.LETTER); document.open(); cb = writer.getDirectContent(); // Set basic metadata document.addAuthor("Peter Brewer"); document.addSubject("Tellervo Series Report for " + s.getDisplayTitle()); // Title Left ColumnText ct = new ColumnText(cb); ct.setSimpleColumn(document.left(), document.top() - 163, 283, document.top(), 20, Element.ALIGN_LEFT); ct.addText(getTitlePDF()); ct.go(); // Barcode ColumnText ct2 = new ColumnText(cb); ct2.setSimpleColumn(370, document.top(15) - 100, document.right(0), document.top(0), 20, Element.ALIGN_RIGHT); ct2.addElement(getBarCode()); ct2.go(); // Timestamp ColumnText ct3 = new ColumnText(cb); ct3.setSimpleColumn(document.left(), document.top() - 223, 283, document.top() - 60, 20, Element.ALIGN_LEFT); ct3.setLeading(0, 1.2f); ct3.addText(getTimestampPDF()); ct3.go(); // Authorship ColumnText ct4 = new ColumnText(cb); ct4.setSimpleColumn(284, document.top() - 223, document.right(10), document.top() - 60, 20, Element.ALIGN_RIGHT); ct4.setLeading(0, 1.2f); ct4.addText(getAuthorshipPDF()); ct4.go(); // Pad text document.add(new Paragraph(" ")); Paragraph p2 = new Paragraph(); p2.setSpacingBefore(50); p2.setSpacingAfter(10); p2.add(new Chunk(" ", bodyFont)); document.add(new Paragraph(p2)); // Ring width table getRingWidthTable(); document.add(getParagraphSpace()); if (s.getSeries() instanceof TridasMeasurementSeries) { // MEASUREMENT SERIES //document.add(getRingRemarks()); document.add(getWoodCompletenessPDF()); document.add(getParagraphSpace()); document.add(getSeriesComments()); document.add(getParagraphSpace()); document.add(getInterpretationPDF()); document.add(getParagraphSpace()); document.add(getElementAndSampleInfo()); } else { // DERIVED SERIES getWJTable(); document.add(getParagraphSpace()); document.add(getSeriesComments()); document.add(getParagraphSpace()); //document.add(getRingRemarks()); } } catch (DocumentException de) { System.err.println(de.getMessage()); } // Close the document document.close(); }
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// www. java 2s .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(); } } }