List of usage examples for com.lowagie.text.pdf PdfPCell getPhrase
public Phrase getPhrase()
Phrase
from this cell. From source file:de.jdufner.sudoku.generator.pdf.PdfPrinterImpl.java
License:Open Source License
private PdfPTable writePdfTable(SudokuData sudokuData) { PdfPTable einzelnesSudoku = new PdfPTable(1); PdfPTable ueberschrift = new PdfPTable(2); PdfPCell linkeZelle = new PdfPCell(new Phrase("ID: " + sudokuData.getId())); linkeZelle.getPhrase().getFont().setSize(9f); linkeZelle.setBorder(Integer.parseInt(getPdfStyle().getProperty("border.none"))); linkeZelle.setHorizontalAlignment(Element.ALIGN_LEFT); ueberschrift.addCell(linkeZelle);//from w w w .ja v a 2 s . co m PdfPCell rechteZelle = new PdfPCell( new Phrase(Level.valueOf(sudokuData.getLevel()).getName() + " (" + sudokuData.getFixed() + ")")); rechteZelle.getPhrase().getFont().setSize(9f); rechteZelle.setBorder(0); rechteZelle.setHorizontalAlignment(Element.ALIGN_RIGHT); ueberschrift.addCell(rechteZelle); PdfPCell obereZelle = new PdfPCell(ueberschrift); obereZelle.setBorder(0); einzelnesSudoku.addCell(obereZelle); PdfCellHandler pdfCellHandler = new PdfCellHandler(SudokuSize.getByUnitSize(sudokuData.getSize()), getPdfStyle()); pdfCellHandler.initialize(); HandlerUtil.forEachCell(SudokuFactory.INSTANCE.buildSudoku(sudokuData.getSudokuAsString()), pdfCellHandler); PdfPCell untereZelle = new PdfPCell(pdfCellHandler.getTable()); untereZelle.setBorder(0); einzelnesSudoku.addCell(untereZelle); return einzelnesSudoku; }
From source file:org.jsondoc.springmvc.pdf.PdfExportView.java
License:Open Source License
public File getPdfFile(String filename) { try {/*w ww.j a va 2 s . com*/ File file = new File(filename + "-v" + jsonDoc.getVersion() + FILE_EXTENSION); FileOutputStream fileout = new FileOutputStream(file); Document document = new Document(); PdfWriter.getInstance(document, fileout); // Header HeaderFooter header = new HeaderFooter(new Phrase("Copyright " + Calendar.getInstance().get(Calendar.YEAR) + " Paybay Networks - All rights reserved"), false); header.setBorder(Rectangle.NO_BORDER); header.setAlignment(Element.ALIGN_LEFT); document.setHeader(header); // Footer HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer); document.open(); //init documentation apiDocs = buildApiDocList(); apiMethodDocs = buildApiMethodDocList(apiDocs); Phrase baseUrl = new Phrase("Base url: " + jsonDoc.getBasePath()); document.add(baseUrl); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); int pos = 1; for (ApiMethodDoc apiMethodDoc : apiMethodDocs) { Phrase phrase = new Phrase(/*"Description: " + */apiMethodDoc.getDescription()); document.add(phrase); document.add(Chunk.NEWLINE); PdfPTable table = new PdfPTable(2); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.getDefaultCell().setBorder(Rectangle.NO_BORDER); table.setWidthPercentage(100); table.setWidths(new int[] { 50, 200 }); // HEADER CELL START TABLE table.addCell(ITextUtils.getHeaderCell("URL")); table.addCell(ITextUtils.getHeaderCell("<baseUrl> " + apiMethodDoc.getPath())); table.completeRow(); // FIRST CELL table.addCell(ITextUtils.getCell("Http Method", 0)); table.addCell(ITextUtils.getCell(apiMethodDoc.getVerb().name(), pos)); pos++; table.completeRow(); // PRODUCES if (!apiMethodDoc.getProduces().isEmpty()) { table.addCell(ITextUtils.getCell("Produces", 0)); table.addCell(ITextUtils.getCell(buildApiMethodProduces(apiMethodDoc), pos)); pos++; table.completeRow(); } // CONSUMES if (!apiMethodDoc.getConsumes().isEmpty()) { table.addCell(ITextUtils.getCell("Consumes", 0)); table.addCell(ITextUtils.getCell(buildApiMethodConsumes(apiMethodDoc), pos)); pos++; table.completeRow(); } // HEADERS if (!apiMethodDoc.getHeaders().isEmpty()) { table.addCell(ITextUtils.getCell("Request headers", 0)); PdfPTable pathParamsTable = new PdfPTable(3); pathParamsTable.setWidths(new int[] { 30, 20, 40 }); pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); for (ApiHeaderDoc apiHeaderDoc : apiMethodDoc.getHeaders()) { PdfPCell boldCell = new PdfPCell(); Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); boldCell.setPhrase(new Phrase(apiHeaderDoc.getName(), fontbold)); boldCell.getPhrase().setFont(new Font(Font.BOLD)); boldCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(boldCell); PdfPCell paramCell = new PdfPCell(); StringBuilder builder = new StringBuilder(); for (String value : apiHeaderDoc.getAllowedvalues()) builder.append(value).append(", "); paramCell.setPhrase(new Phrase("Allowed values: " + builder.toString())); paramCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(paramCell); paramCell.setPhrase(new Phrase(apiHeaderDoc.getDescription())); pathParamsTable.addCell(paramCell); pathParamsTable.completeRow(); } PdfPCell bluBorderCell = new PdfPCell(pathParamsTable); bluBorderCell.setBorder(Rectangle.NO_BORDER); bluBorderCell.setBorderWidthRight(1f); bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR); table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos)); pos++; table.completeRow(); } // PATH PARAMS if (!apiMethodDoc.getPathparameters().isEmpty()) { table.addCell(ITextUtils.getCell("Path params", 0)); PdfPTable pathParamsTable = new PdfPTable(3); pathParamsTable.setWidths(new int[] { 30, 15, 40 }); pathParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); pathParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); for (ApiParamDoc apiParamDoc : apiMethodDoc.getPathparameters()) { PdfPCell boldCell = new PdfPCell(); Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold)); boldCell.getPhrase().setFont(new Font(Font.BOLD)); boldCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(boldCell); PdfPCell paramCell = new PdfPCell(); paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText())); paramCell.setBorder(Rectangle.NO_BORDER); pathParamsTable.addCell(paramCell); paramCell.setPhrase(new Phrase(apiParamDoc.getDescription())); pathParamsTable.addCell(paramCell); pathParamsTable.completeRow(); } PdfPCell bluBorderCell = new PdfPCell(pathParamsTable); bluBorderCell.setBorder(Rectangle.NO_BORDER); bluBorderCell.setBorderWidthRight(1f); bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR); table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos)); pos++; table.completeRow(); } // QUERY PARAMS if (!apiMethodDoc.getQueryparameters().isEmpty()) { table.addCell(ITextUtils.getCell("Query params", 0)); PdfPTable queryParamsTable = new PdfPTable(3); queryParamsTable.setWidths(new int[] { 30, 15, 40 }); queryParamsTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); queryParamsTable.getDefaultCell().setBorder(Rectangle.NO_BORDER); for (ApiParamDoc apiParamDoc : apiMethodDoc.getQueryparameters()) { PdfPCell boldCell = new PdfPCell(); Font fontbold = FontFactory.getFont("Times-Roman", 12, Font.BOLD); boldCell.setPhrase(new Phrase(apiParamDoc.getName(), fontbold)); boldCell.getPhrase().setFont(new Font(Font.BOLD)); boldCell.setBorder(Rectangle.NO_BORDER); queryParamsTable.addCell(boldCell); PdfPCell paramCell = new PdfPCell(); paramCell.setPhrase(new Phrase(apiParamDoc.getJsondocType().getOneLineText())); paramCell.setBorder(Rectangle.NO_BORDER); queryParamsTable.addCell(paramCell); paramCell.setPhrase(new Phrase( apiParamDoc.getDescription() + ", mandatory: " + apiParamDoc.getRequired())); queryParamsTable.addCell(paramCell); queryParamsTable.completeRow(); } PdfPCell bluBorderCell = new PdfPCell(queryParamsTable); bluBorderCell.setBorder(Rectangle.NO_BORDER); bluBorderCell.setBorderWidthRight(1f); bluBorderCell.setBorderColorRight(Colors.CELL_BORDER_COLOR); table.addCell(ITextUtils.setOddEvenStyle(bluBorderCell, pos)); pos++; table.completeRow(); } // BODY OBJECT if (null != apiMethodDoc.getBodyobject()) { table.addCell(ITextUtils.getCell("Body object:", 0)); String jsonObject = buildJsonFromTemplate(apiMethodDoc.getBodyobject().getJsondocTemplate()); table.addCell(ITextUtils.getCell(jsonObject, pos)); pos++; table.completeRow(); } // RESPONSE OBJECT table.addCell(ITextUtils.getCell("Json response:", 0)); table.addCell( ITextUtils.getCell(apiMethodDoc.getResponse().getJsondocType().getOneLineText(), pos)); pos++; table.completeRow(); // RESPONSE STATUS CODE table.addCell(ITextUtils.getCell("Status code:", 0)); table.addCell(ITextUtils.getCell(apiMethodDoc.getResponsestatuscode(), pos)); pos++; table.completeRow(); table.setSpacingAfter(10f); table.setSpacingBefore(5f); document.add(table); } document.close(); return file; } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return null; }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.table.rtf.itext.PatchRtfCell.java
License:Open Source License
/** * Imports the Cell properties into the PatchRtfCell * * @param cell//from w ww.j a va 2s . c om * The PdfPCell to import * @since 2.1.3 */ private void importCell(PdfPCell cell) { this.content = new ArrayList<RtfBasicElement>(); if (cell == null) { this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER, this.parentRow.getParentTable().getBorders()); return; } // padding this.cellPadding = (int) this.parentRow.getParentTable().getCellPadding(); this.cellPaddingBottom = cell.getPaddingBottom(); this.cellPaddingTop = cell.getPaddingTop(); this.cellPaddingRight = cell.getPaddingRight(); this.cellPaddingLeft = cell.getPaddingLeft(); // BORDERS this.borders = new PatchRtfBorderGroup(this.document, PatchRtfBorder.CELL_BORDER, cell.getBorder(), cell.getBorderWidth(), cell.getBorderColor()); // border colors this.border = cell.getBorder(); this.borderColor = cell.getBorderColor(); this.borderColorBottom = cell.getBorderColorBottom(); this.borderColorTop = cell.getBorderColorTop(); this.borderColorLeft = cell.getBorderColorLeft(); this.borderColorRight = cell.getBorderColorRight(); // border widths this.borderWidth = cell.getBorderWidth(); this.borderWidthBottom = cell.getBorderWidthBottom(); this.borderWidthTop = cell.getBorderWidthTop(); this.borderWidthLeft = cell.getBorderWidthLeft(); this.borderWidthRight = cell.getBorderWidthRight(); this.colspan = cell.getColspan(); this.rowspan = 1; // cell.getRowspan(); // if(cell.getRowspan() > 1) { // this.mergeType = MERGE_VERT_PARENT; // } this.verticalAlignment = cell.getVerticalAlignment(); if (cell.getBackgroundColor() == null) { this.backgroundColor = new RtfColor(this.document, 255, 255, 255); } else { this.backgroundColor = new RtfColor(this.document, cell.getBackgroundColor()); } // does it have column composite info? java.util.List compositeElements = cell.getCompositeElements(); if (compositeElements != null) { Iterator cellIterator = compositeElements.iterator(); // does it have column info? Paragraph container = null; while (cellIterator.hasNext()) { try { Element element = (Element) cellIterator.next(); // should we wrap it in a paragraph if (!(element instanceof Paragraph) && !(element instanceof List)) { if (container != null) { container.add(element); } else { container = new Paragraph(); container.setAlignment(cell.getHorizontalAlignment()); container.add(element); } } else { if (container != null) { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } container = null; } // if horizontal alignment is undefined overwrite // with that of enclosing cell if (element instanceof Paragraph && ((Paragraph) element).getAlignment() == Element.ALIGN_UNDEFINED) { ((Paragraph) element).setAlignment(cell.getHorizontalAlignment()); } RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(element); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } } catch (DocumentException de) { de.printStackTrace(); } } if (container != null) { try { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(container); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } catch (DocumentException de) { de.printStackTrace(); } } } // does it have image info? Image img = cell.getImage(); if (img != null) { try { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(img); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // does it have phrase info? Phrase phrase = cell.getPhrase(); if (phrase != null) { try { RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(phrase); for (int i = 0; i < rtfElements.length; i++) { rtfElements[i].setInTable(true); this.content.add(rtfElements[i]); } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // does it have table info? PdfPTable table = cell.getTable(); if (table != null) { this.add(table); // try { // RtfBasicElement[] rtfElements = this.document.getMapper().mapElement(table); // for (int i = 0; i < rtfElements.length; i++) { // rtfElements[i].setInTable(true); // this.content.add(rtfElements[i]); // } // } catch (DocumentException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } }
From source file:org.unitime.timetable.webutil.pdf.PdfEventTableBuilder.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 a 2s. c o m*/ if (cell.getPhrase() == null) { Chunk ch = new Chunk(text, PdfFont.getSmallFont(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.getSmallFont(bold, italic, color))); } }
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 ww . j a v a 2 s.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;/* www . ja v a 2 s .co m*/ 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.pdf.PdfInstructionalOfferingTableBuilder.java
License:Open Source License
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;//w ww . j av a 2 s . c o m } 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, PreferenceLevel.prolog2abbv(pref.getPrefLevel().getPrefProlog()) + " " + 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; }
From source file:org.unitime.timetable.webutil.PdfWebTable.java
License:Open Source License
private float addImage(PdfPCell cell, String name) { try {/*from w w w. j av a2 s. c o m*/ 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 w ww.j a v a 2s. co 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;/*from www. java 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))); } }