List of usage examples for com.lowagie.text.pdf PdfPCell setPhrase
public void setPhrase(Phrase phrase)
Phrase
for this cell. From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color, boolean newLine) { if (text == null) return;/*from w w w . j a v a2s .c o m*/ if (cell.getPhrase() == null) { Chunk ch = new Chunk(text, PdfFont.getFont(bold, italic, color)); cell.setPhrase(new Paragraph(ch)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(orientation); } else { cell.getPhrase().add(new Chunk((newLine ? "\n" : "") + text, PdfFont.getFont(bold, italic, color))); } }
From source file:org.unitime.timetable.webutil.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
private PdfPCell pdfBuildTimePrefCell(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, boolean isEditable) { Color color = (isEditable ? sEnableColor : sDisableColor); Assignment a = null;/*w w w . j av a 2 s . com*/ if (getDisplayTimetable() && isShowTimetable() && classAssignment != null && prefGroup instanceof Class_) { try { a = classAssignment.getAssignment((Class_) prefGroup); } catch (Exception e) { Debug.error(e); } } PdfPCell cell = createCell(); for (Iterator i = prefGroup.effectivePreferences(TimePref.class).iterator(); i.hasNext();) { TimePref tp = (TimePref) i.next(); RequiredTimeTable rtt = tp.getRequiredTimeTable(a == null ? null : a.getTimeLocation()); if (getGridAsText()) { addText(cell, rtt.getModel().toString().replaceAll(", ", "\n"), false, false, Element.ALIGN_LEFT, color, true); } else { try { rtt.getModel().setDefaultSelection(getDefaultTimeGridSize()); if (rtt.getModel().isExactTime()) { addText(cell, rtt.exactTime(false), false, false, Element.ALIGN_LEFT, color, true); } else { java.awt.Image awtImage = rtt.createBufferedImage(getTimeVertival()); Image img = Image.getInstance(awtImage, Color.WHITE); Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); } else { cell.getPhrase().add(ck); } } } catch (Exception e) { e.printStackTrace(); } } } return cell; }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
private float addImage(PdfPCell cell, String name) { try {/*w ww .j a va2 s . c om*/ java.awt.Image awtImage = (java.awt.Image) iImages.get(name); if (awtImage == null) return 0; Image img = Image.getInstance(awtImage, Color.WHITE); Chunk ck = new Chunk(img, 0, 0); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(ck)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(ck); } return awtImage.getWidth(null); } catch (Exception e) { return 0; } }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) {//from www . ja v a 2s. c o m Font font = PdfFont.getFont(bold, italic, underline, color); Chunk chunk = new Chunk(text, font); if (bgColor != null) chunk.setBackground(bgColor); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(chunk)); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(chunk); } float width = 0; if (text.indexOf('\n') >= 0) { for (StringTokenizer s = new StringTokenizer(text, "\n"); s.hasMoreTokens();) width = Math.max(width, font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize())); } else width = Math.max(width, font.getBaseFont().getWidthPoint(text, font.getSize())); return width; }
From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java
License:Open Source License
public void addText(PdfPCell cell, String text, boolean bold) { if (text == null) return;/* www. j av a 2 s . c om*/ if (text.indexOf("<span") >= 0) text = text.replaceAll("</span>", "").replaceAll("<span .*>", ""); text = text.replaceAll("<br>", "\n"); text = text.replaceAll("<BR>", "\n"); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(text, PdfFont.getFont(bold))); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(new Chunk("\n" + text, PdfFont.getFont(bold))); } }
From source file:org.unitime.timetable.webutil.timegrid.PdfTimetableGridTable.java
License:Open Source License
public void addText(PdfPCell cell, String text, boolean bold) { if (text == null) return;/*from w w w . j ava 2s . c om*/ if (text.indexOf("<span") >= 0) text = text.replaceAll("</span>", "").replaceAll("<span .*>", ""); if (cell.getPhrase() == null) { cell.setPhrase(new Paragraph(text, PdfFont.getSmallFont(bold))); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); } else { cell.getPhrase().add(new Chunk("\n" + text, PdfFont.getSmallFont(bold))); } }
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 w w w. j a v a 2 s . c om*/ 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: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. */// www .j a v a 2 s . co 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 createLogoHeader() { float[] tableWidths; PdfPCell cell = new PdfPCell(); //tableWidths = new float[]{ 1.5f, 2.5f }; //PdfPTable infoTable = new PdfPTable(tableWidths); PdfPTable infoTable = new PdfPTable(1); try {/*from w w w .ja v a2 s. c om*/ String filename = ""; if (props.getProperty("multisites") != null && "on".equalsIgnoreCase(props.getProperty("multisites"))) { DocumentDAO documentDao = (DocumentDAO) SpringUtils.getBean("documentDAO"); SiteDao siteDao = (SiteDao) SpringUtils.getBean("siteDao"); Site site = siteDao.getByLocation(reqFrm.siteName); if (site != null) { if (site.getSiteLogoId() != null) { org.oscarehr.document.model.Document d = documentDao .getDocument(String.valueOf(site.getSiteLogoId())); String dir = props.getProperty("DOCUMENT_DIR"); filename = dir.concat(d.getDocfilename()); } else { //If no logo file uploaded for this site, use the default one defined in oscar properties file. filename = props.getProperty("faxLogoInConsultation"); } } } else { filename = props.getProperty("faxLogoInConsultation"); } FileInputStream fileInputStream = new FileInputStream(filename); byte[] faxLogImage = new byte[1024 * 256]; fileInputStream.read(faxLogImage); Image image = Image.getInstance(faxLogImage); image.scalePercent(80f); image.setBorder(0); cell = new PdfPCell(image); cell.setBorder(0); infoTable.addCell(cell); } catch (Exception e) { logger.error("Unexpected error.", e); } // 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
private PdfPTable createReplyHeader() { PdfPCell cell; PdfPTable infoTable = new PdfPTable(1); cell = new PdfPCell(new Phrase("", headerFont)); cell.setBorder(0);//from w w w.ja v a 2 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; }