List of usage examples for com.lowagie.text.pdf PdfPCell setVerticalAlignment
public void setVerticalAlignment(int verticalAlignment)
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 w ww. j a va 2 s . 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 PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor);/*from w w w. ja va2s .c o m*/ cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(1); cell.setBorderWidthBottom(1); cell.setBorderWidthLeft(1); cell.setBorderWidthRight(1); return cell; }
From source file:org.unitime.timetable.webutil.timegrid.PdfExamGridTable.java
License:Open Source License
public PdfPCell createCellNoBorder() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor);//from www . j av a 2s .com cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); return cell; }
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;/*from w ww . j a va 2 s .c o m*/ 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 ww w . java2 s. co m*/ 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 www .j a v a 2 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: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. *//*from ww w . j a v a 2 s .c om*/ 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.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();//from w w w . jav a2 s . com //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:sms.ReportForms.java
public PdfPCell createTextCell(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD, 16, Font.BOLD)); // p.setFont(Font.BOLD); p.setAlignment(Element.ALIGN_CENTER); p.add(text);/*from w w w . ja va 2s. c om*/ cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }
From source file:storemanagment.Printing.java
public PdfPCell createTextCellNb(String text) { PdfPCell cell = new PdfPCell(); Paragraph p = new Paragraph(); p.setAlignment(Element.ALIGN_CENTER); p.add(text);// w w w . j a v a 2 s . co m cell.addElement(p); cell.setBorder(Rectangle.NO_BORDER); cell.setVerticalAlignment(Rectangle.NO_BORDER); return cell; }