Java Code Examples for com.lowagie.text.pdf.PdfPCell#getPhrase()
The following examples show how to use
com.lowagie.text.pdf.PdfPCell#getPhrase() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfWebTable.java From unitime with Apache License 2.0 | 6 votes |
private float addImage(PdfPCell cell, String name) { try { 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; } }
Example 2
Source File: PdfWebTable.java From unitime with Apache License 2.0 | 6 votes |
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) { 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; }
Example 3
Source File: PdfTimetableGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addText(PdfPCell cell, String text, boolean bold) { if (text==null) return; 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))); } }
Example 4
Source File: PdfTimetableGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception { if (text==null) return; 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); } }
Example 5
Source File: PdfExamGridTable.java From unitime with Apache License 2.0 | 5 votes |
public void addText(PdfPCell cell, String text, boolean bold) { if (text==null) return; 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))); } }
Example 6
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 5 votes |
public void addText(PdfPCell cell, String text, boolean bold, boolean italic, int orientation, Color color, boolean newLine) { if (text==null) return; 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))); } }
Example 7
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 5 votes |
private PdfPCell pdfBuildPreferenceCell(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, Class[] prefTypes, boolean isEditable){ if (!isEditable) return createCell(); Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); boolean noRoomPrefs = false; if (prefGroup instanceof Class_ && ((Class_)prefGroup).getNbrRooms().intValue()==0) { noRoomPrefs = true; } if (prefGroup instanceof SchedulingSubpart && ((SchedulingSubpart)prefGroup).getInstrOfferingConfig().isUnlimitedEnrollment().booleanValue()) noRoomPrefs = true; for (int i=0;i<prefTypes.length;i++) { Class prefType = prefTypes[i]; if (noRoomPrefs) { if (//prefType.equals(RoomPref.class) || prefType.equals(RoomGroupPref.class) || prefType.equals(RoomFeaturePref.class) || prefType.equals(BuildingPref.class)) continue; } for (Iterator j=prefGroup.effectivePreferences(prefType).iterator();j.hasNext();) { Preference pref = (Preference)j.next(); addText(cell, pref.getPrefLevel().getAbbreviation()+" "+pref.preferenceText(), false, false, Element.ALIGN_LEFT, (!isEditable ? color : pref.getPrefLevel().awtPrefcolor()), true); } } if (noRoomPrefs && cell.getPhrase()==null) addText(cell, "N/A", false, true, Element.ALIGN_LEFT, color, true); return cell; }