com.lowagie.text.Element Java Examples
The following examples show how to use
com.lowagie.text.Element.
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: PageNumbersWatermarkTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Generates a document with a header containing Page x of y and with a Watermark on every page. */ @Test public void main() throws Exception { // step 1: creating the document Document doc = new Document(PageSize.A4, 50, 50, 100, 72); // step 2: creating the writer PdfWriter writer = PdfWriter.getInstance(doc, PdfTestBase.getOutputStream( "pageNumbersWatermark.pdf")); // step 3: initialisations + opening the document writer.setPageEvent(new PageNumbersWatermarkTest()); doc.open(); // step 4: adding content String text = "some padding text "; for (int k = 0; k < 10; ++k) { text += text; } Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); doc.add(p); // step 5: closing the document doc.close(); }
Example #2
Source File: SpaceWordRatioTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Space Word Ratio. */ @Test public void main() throws Exception { // step 1 Document document = new Document(PageSize.A4, 50, 350, 50, 50); // step 2 PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("spacewordratio.pdf")); // step 3 document.open(); // step 4 String text = "Flanders International Filmfestival Ghent - Internationaal Filmfestival van Vlaanderen Gent"; Paragraph p = new Paragraph(text); p.setAlignment(Element.ALIGN_JUSTIFIED); document.add(p); document.newPage(); writer.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO); document.add(p); // step 5 document.close(); }
Example #3
Source File: PdfProcessInformationsReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeProcessInformations(ProcessInformations processInformations) { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(processInformations.getUser()); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(processInformations.getPid())); if (!windows) { addCell(percentFormat.format(processInformations.getCpuPercentage())); addCell(percentFormat.format(processInformations.getMemPercentage())); } addCell(integerFormat.format(processInformations.getVsz())); if (!windows) { addCell(integerFormat.format(processInformations.getRss())); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(processInformations.getTty()); addCell(processInformations.getStat()); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(processInformations.getStart()); } addCell(processInformations.getCpuTime()); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(processInformations.getCommand()); }
Example #4
Source File: PdfLogicalPageDrawable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
public ColumnText reconfigure( PdfContentByte cb, Phrase p ) { float filledWidth = ColumnText.getWidth( p, runDirection, 0 ) + 0.5f; ColumnText ct = new ColumnText( cb ); ct.setRunDirection( runDirection ); if ( alignment == Element.ALIGN_LEFT ) { ct.setSimpleColumn( llx, lly, llx + filledWidth, ury, leading, alignment ); } else if ( alignment == Element.ALIGN_RIGHT ) { ct.setSimpleColumn( urx - filledWidth, lly, urx, ury, leading, alignment ); } else if ( alignment == Element.ALIGN_CENTER ) { float delta = ( ( urx - llx ) - filledWidth ) / 2; ct.setSimpleColumn( urx + delta, lly, urx - delta, ury, leading, alignment ); } else { ct.setSimpleColumn( llx, lly, urx, ury, leading, alignment ); } return ct; }
Example #5
Source File: Barcode39.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** Creates a new Barcode39. */ public Barcode39() { try { x = 0.8f; n = 2; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; generateChecksum = false; checksumText = false; startStopText = true; extended = false; } catch (Exception e) { throw new ExceptionConverter(e); } }
Example #6
Source File: CustomerLoadServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
protected void writeCustomerSectionTitle(Document pdfDoc, String customerNameLine) { Font font = FontFactory.getFont(FontFactory.COURIER, 8, Font.BOLD + Font.UNDERLINE); Paragraph paragraph = new Paragraph(); paragraph.setAlignment(Element.ALIGN_LEFT); paragraph.add(new Chunk(customerNameLine, font)); // blank line paragraph.add(new Chunk("", font)); try { pdfDoc.add(paragraph); } catch (DocumentException e) { LOG.error("iText DocumentException thrown when trying to write content.", e); throw new RuntimeException("iText DocumentException thrown when trying to write content.", e); } }
Example #7
Source File: PdfJndiReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeJndiBinding(JndiBinding jndiBinding) throws BadElementException, IOException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final String name = jndiBinding.getName(); final String className = jndiBinding.getClassName(); final String contextPath = jndiBinding.getContextPath(); final String value = jndiBinding.getValue(); if (contextPath != null) { final Image image = getFolderImage(); final Phrase phrase = new Phrase("", cellFont); phrase.add(new Chunk(image, 0, 0)); phrase.add(new Chunk(" " + name)); addCell(phrase); } else { addCell(name); } addCell(className != null ? className : ""); addCell(value != null ? value : ""); }
Example #8
Source File: BarcodeCodabar.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** Creates a new BarcodeCodabar. */ public BarcodeCodabar() { try { x = 0.8f; n = 2; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; generateChecksum = false; checksumText = false; startStopText = false; codeType = CODABAR; } catch (Exception e) { throw new ExceptionConverter(e); } }
Example #9
Source File: BarcodeInter25.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** Creates new BarcodeInter25 */ public BarcodeInter25() { try { x = 0.8f; n = 2; font = BaseFont.createFont("Helvetica", "winansi", false); size = 8; baseline = size; barHeight = size * 3; textAlignment = Element.ALIGN_CENTER; generateChecksum = false; checksumText = false; } catch (Exception e) { throw new ExceptionConverter(e); } }
Example #10
Source File: MarkupParser.java From MesquiteCore with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns an object based on a tag and its attributes. * @param attributes a Properties object with the tagname and the attributes of the tag. * @return an iText object */ public Element getObject(Properties attributes) { String key = getKey(attributes); Properties styleattributes = (Properties)stylecache.get(key); if (styleattributes != null && MarkupTags.CSS_VALUE_HIDDEN.equals(styleattributes.get(MarkupTags.CSS_KEY_VISIBILITY))) { return null; } String display = styleattributes.getProperty(MarkupTags.CSS_KEY_DISPLAY); Element element = null; if (MarkupTags.CSS_VALUE_INLINE.equals(display)) { element = retrievePhrase(getFont(attributes), styleattributes); } else if (MarkupTags.CSS_VALUE_BLOCK.equals(display)) { element = retrieveParagraph(getFont(attributes), styleattributes); } else if (MarkupTags.CSS_VALUE_LISTITEM.equals(display)) { element = retrieveListItem(getFont(attributes), styleattributes); } else if (MarkupTags.CSS_VALUE_TABLECELL.equals(display)) { element = retrieveTableCell(getFont(attributes), styleattributes); } else if (MarkupTags.CSS_VALUE_TABLE.equals(display)) { element = retrieveTable(styleattributes); } return element; }
Example #11
Source File: LineSeparator.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Draws a horizontal line. * @param canvas the canvas to draw on * @param leftX the left x coordinate * @param rightX the right x coordindate * @param y the y coordinate */ public void drawLine(PdfContentByte canvas, float leftX, float rightX, float y) { float w; if (getPercentage() < 0) w = -getPercentage(); else w = (rightX - leftX) * getPercentage() / 100.0f; float s; switch (getAlignment()) { case Element.ALIGN_LEFT: s = 0; break; case Element.ALIGN_RIGHT: s = rightX - leftX - w; break; default: s = (rightX - leftX - w) / 2; break; } canvas.setLineWidth(getLineWidth()); if (getLineColor() != null) canvas.setColorStroke(getLineColor()); canvas.moveTo(s + leftX, y + offset); canvas.lineTo(s + w + leftX, y + offset); canvas.stroke(); }
Example #12
Source File: PdfCacheInformationsReport.java From javamelody with Apache License 2.0 | 6 votes |
@Override void toPdf() throws DocumentException { writeHeader(); for (final CacheInformations cacheInformations : cacheInformationsList) { nextRow(); writeCacheInformations(cacheInformations); } addTableToDocument(); if (!hitsRatioEnabled) { final Paragraph statisticsEnabledParagraph = new Paragraph( getString("caches_statistics_enable"), cellFont); statisticsEnabledParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(statisticsEnabledParagraph); } addConfigurationReference(); }
Example #13
Source File: HtmlEncoder.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Translates the alignment value. * * @param alignment the alignment value * @return the translated value */ public static String getAlignment(int alignment) { switch(alignment) { case Element.ALIGN_LEFT: return HtmlTags.ALIGN_LEFT; case Element.ALIGN_CENTER: return HtmlTags.ALIGN_CENTER; case Element.ALIGN_RIGHT: return HtmlTags.ALIGN_RIGHT; case Element.ALIGN_JUSTIFIED: case Element.ALIGN_JUSTIFIED_ALL: return HtmlTags.ALIGN_JUSTIFIED; case Element.ALIGN_TOP: return HtmlTags.ALIGN_TOP; case Element.ALIGN_MIDDLE: return HtmlTags.ALIGN_MIDDLE; case Element.ALIGN_BOTTOM: return HtmlTags.ALIGN_BOTTOM; case Element.ALIGN_BASELINE: return HtmlTags.ALIGN_BASELINE; default: return ""; } }
Example #14
Source File: RTFPrinter.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
private void computeCellStyle( final RenderBox content, final Cell cell ) { final ElementAlignment verticalAlign = content.getNodeLayoutProperties().getVerticalAlignment(); if ( ElementAlignment.BOTTOM.equals( verticalAlign ) ) { cell.setVerticalAlignment( Element.ALIGN_BOTTOM ); } else if ( ElementAlignment.MIDDLE.equals( verticalAlign ) ) { cell.setVerticalAlignment( Element.ALIGN_MIDDLE ); } else { cell.setVerticalAlignment( Element.ALIGN_TOP ); } final ElementAlignment textAlign = (ElementAlignment) content.getStyleSheet().getStyleProperty( ElementStyleKeys.ALIGNMENT ); if ( ElementAlignment.RIGHT.equals( textAlign ) ) { cell.setHorizontalAlignment( Element.ALIGN_RIGHT ); } else if ( ElementAlignment.JUSTIFY.equals( textAlign ) ) { cell.setHorizontalAlignment( Element.ALIGN_JUSTIFIED ); } else if ( ElementAlignment.CENTER.equals( textAlign ) ) { cell.setHorizontalAlignment( Element.ALIGN_CENTER ); } else { cell.setHorizontalAlignment( Element.ALIGN_LEFT ); } }
Example #15
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 6 votes |
private PdfPCell pdfBuildExamPeriod(ExamAssignmentProxy examAssignment, TreeSet exams, boolean isEditable) { StringBuffer sb = new StringBuffer(); for (Iterator i=exams.iterator();i.hasNext();) { Exam exam = (Exam)i.next(); if (examAssignment!=null && examAssignment.getExamTypeId().equals(exam.getExamType().getUniqueId())) { ExamAssignment ea = examAssignment.getAssignment(exam.getUniqueId()); if (ea==null && !isShowExamName()) continue; sb.append(ea==null?"":ea.getPeriodAbbreviation()); } else { if (exam.getAssignedPeriod()==null && !isShowExamName()) continue; sb.append(exam.getAssignedPeriod()==null?"":exam.getAssignedPeriod().getAbbreviation()); } if (i.hasNext()) sb.append("\n"); } Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, color, true); return cell; }
Example #16
Source File: DuplicateRowOnPageSplitTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
private static void anadirTextoTabla(PdfPTable tabla, String titulo, String desc) { PdfPCell cell = new PdfPCell(); disableBorders(cell); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_LEFT); cell.addElement(new Phrase(titulo,fuente10)); tabla.addCell(cell); cell = new PdfPCell(); disableBorders(cell); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.addElement(new Phrase(defaultString(desc),fuente10)); tabla.addCell(cell); }
Example #17
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 5 votes |
public PdfPCell createCell() { PdfPCell cell = new PdfPCell(); cell.setBorderColor(sBorderColor); cell.setPadding(3); cell.setBorderWidth(0); cell.setVerticalAlignment(Element.ALIGN_TOP); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBackgroundColor(iBgColor); return cell; }
Example #18
Source File: PdfSessionInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeSession(SessionInformations session) throws IOException, BadElementException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(session.getId()); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(durationFormat.format(session.getLastAccess())); addCell(durationFormat.format(session.getAge())); addCell(expiryFormat.format(session.getExpirationDate())); addCell(integerFormat.format(session.getAttributeCount())); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); if (session.isSerializable()) { addCell(getString("oui")); } else { final Phrase non = new Phrase(getString("non"), severeCellFont); addCell(non); } defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(session.getSerializedSize())); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final String remoteAddr = session.getRemoteAddr(); if (remoteAddr == null) { addCell(""); } else { addCell(remoteAddr); } defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); writeCountry(session); writeBrowserAndOs(session); if (displayUser) { defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final String remoteUser = session.getRemoteUser(); if (remoteUser == null) { addCell(""); } else { addCell(remoteUser); } } }
Example #19
Source File: PageNumbersWatermarkTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see com.lowagie.text.pdf.PdfPageEventHelper#onStartPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document) */ public void onStartPage(PdfWriter writer, Document document) { if (writer.getPageNumber() < 3) { PdfContentByte cb = writer.getDirectContentUnder(); cb.saveState(); cb.setColorFill(Color.pink); cb.beginText(); cb.setFontAndSize(helv, 48); cb.showTextAligned(Element.ALIGN_CENTER, "My Watermark Under " + writer.getPageNumber(), document.getPageSize().getWidth() / 2, document.getPageSize().getHeight() / 2, 45); cb.endText(); cb.restoreState(); } }
Example #20
Source File: PdfJobInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
private void addConfigurationReference() throws DocumentException { final Anchor quartzAnchor = new Anchor("Configuration reference", PdfFonts.BLUE.getFont()); quartzAnchor.setName("Quartz configuration reference"); quartzAnchor.setReference("http://www.quartz-scheduler.org/documentation/"); quartzAnchor.setFont(PdfFonts.BLUE.getFont()); final Paragraph quartzParagraph = new Paragraph(); quartzParagraph.add(quartzAnchor); quartzParagraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(quartzParagraph); }
Example #21
Source File: HTMLWorker.java From sakai with Educational Community License v2.0 | 5 votes |
public void endDocument() { try { for (int k = 0; k < stack.size(); ++k) document.add((Element)stack.elementAt(k)); if (currentParagraph != null) document.add(currentParagraph); currentParagraph = null; } catch (Exception e) { throw new ExceptionConverter(e); } }
Example #22
Source File: PdfCell.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Sets the bottom of the Rectangle and determines the proper {link #verticalOffset} * to appropriately align the contents vertically. * @param value */ public void setBottom(float value) { super.setBottom(value); float firstLineRealHeight = firstLineRealHeight(); float totalHeight = ury - value; // can't use top (already compensates for cellspacing) float nonContentHeight = (cellpadding() * 2f) + (cellspacing() * 2f); nonContentHeight += getBorderWidthInside(TOP) + getBorderWidthInside(BOTTOM); float interiorHeight = totalHeight - nonContentHeight; float extraHeight = 0.0f; switch (verticalAlignment) { case Element.ALIGN_BOTTOM: extraHeight = interiorHeight - contentHeight; break; case Element.ALIGN_MIDDLE: extraHeight = (interiorHeight - contentHeight) / 2.0f; break; default: // ALIGN_TOP extraHeight = 0f; } extraHeight += cellpadding() + cellspacing(); extraHeight += getBorderWidthInside(TOP); if (firstLine != null) { firstLine.height = firstLineRealHeight + extraHeight; } }
Example #23
Source File: DefaultPdfDataEntryFormService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
private PdfPTable getProgramStageMainTable() { PdfPTable mainTable = new PdfPTable( 1 ); // Code 1 mainTable.setTotalWidth( 800f ); mainTable.setLockedWidth( true ); mainTable.setHorizontalAlignment( Element.ALIGN_LEFT ); return mainTable; }
Example #24
Source File: PdfCell.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
private void addList(List list, float left, float right, int alignment) { PdfChunk chunk; PdfChunk overflow; ArrayList allActions = new ArrayList(); processActions(list, null, allActions); int aCounter = 0; for (Iterator it = list.getItems().iterator(); it.hasNext();) { Element ele = (Element)it.next(); switch (ele.type()) { case Element.LISTITEM: ListItem item = (ListItem)ele; line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading()); line.setListItem(item); for (Iterator j = item.getChunks().iterator(); j.hasNext();) { chunk = new PdfChunk((Chunk) j.next(), (PdfAction) (allActions.get(aCounter++))); while ((overflow = line.add(chunk)) != null) { addLine(line); line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading()); chunk = overflow; } line.resetAlignment(); addLine(line); line = new PdfLine(left + item.getIndentationLeft(), right, alignment, leading); } break; case Element.LIST: List sublist = (List)ele; addList(sublist, left + sublist.getIndentationLeft(), right, alignment); break; } } }
Example #25
Source File: PdfInstructionalOfferingTableBuilder.java From unitime with Apache License 2.0 | 5 votes |
private PdfPCell pdfBuildAssignedTime(ClassAssignmentProxy classAssignment, PreferenceGroup prefGroup, boolean isEditable){ Color color = (isEditable?sEnableColor:sDisableColor); PdfPCell cell = createCell(); if (classAssignment!=null && prefGroup instanceof Class_) { Class_ aClass = (Class_) prefGroup; Assignment a = null; AssignmentPreferenceInfo p = null; try { a = classAssignment.getAssignment(aClass); p = classAssignment.getAssignmentInfo((Class_)prefGroup); } catch (Exception e) { Debug.error(e); } if (a!=null) { StringBuffer sb = new StringBuffer(); Integer firstDay = ApplicationProperty.TimePatternFirstDayOfWeek.intValue(); for (int i = 0; i < CONSTANTS.shortDays().length; i++) { int idx = (firstDay == null ? i : (i + firstDay) % 7); if ((Constants.DAY_CODES[idx] & a.getTimeLocation().getDayCode()) != 0) sb.append(CONSTANTS.shortDays()[idx]); } sb.append(" "); sb.append(a.getTimeLocation().getStartTimeHeader(CONSTANTS.useAmPm())); sb.append("-"); sb.append(a.getTimeLocation().getEndTimeHeader(CONSTANTS.useAmPm())); addText(cell, sb.toString(), false, false, Element.ALIGN_LEFT, (p == null || !isEditable ? color : PreferenceLevel.int2awtColor(p.getTimePreference(), color)), true); } } return cell; }
Example #26
Source File: PdfHotspotsReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeHotspot(SampledMethod hotspot) { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(hotspot.getClassName() + '.' + hotspot.getMethodName()); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); final double percent = 100d * hotspot.getCount() / totalCount; addCell(percentFormat.format(percent)); }
Example #27
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 #28
Source File: PdfRequestAndGraphDetailReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeRequestValues(CounterRequest aRequest, boolean allChildHitsDisplayed) { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(aRequest.getMean())); addCell(integerFormat.format(aRequest.getMaximum())); addCell(integerFormat.format(aRequest.getStandardDeviation())); if (aRequest.getCpuTimeMean() >= 0) { addCell(integerFormat.format(aRequest.getCpuTimeMean())); } else { addCell(""); } if (isAllocatedKBytesDisplayed()) { if (aRequest.getAllocatedKBytesMean() >= 0) { addCell(integerFormat.format(aRequest.getAllocatedKBytesMean())); } else { addCell(""); } } addCell(systemErrorFormat.format(aRequest.getSystemErrorPercentage())); if (allChildHitsDisplayed) { final boolean childHitsDisplayed = aRequest.hasChildHits(); if (childHitsDisplayed) { addCell(integerFormat.format(aRequest.getChildHitsMean())); } else { addCell(""); } if (childHitsDisplayed) { addCell(integerFormat.format(aRequest.getChildDurationsMean())); } else { addCell(""); } } }
Example #29
Source File: NamedActionsTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a document with Named Actions. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(PageSize.A4, 50, 50, 50, 50); // step 2: we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NamedActions.pdf")); // step 3: we open the document document.open(); // step 4: we add some content Paragraph p = new Paragraph(new Chunk("Click to print").setAction(new PdfAction(PdfAction.PRINTDIALOG))); PdfPTable table = new PdfPTable(4); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(new Phrase(new Chunk("First Page").setAction(new PdfAction(PdfAction.FIRSTPAGE)))); table.addCell(new Phrase(new Chunk("Prev Page").setAction(new PdfAction(PdfAction.PREVPAGE)))); table.addCell(new Phrase(new Chunk("Next Page").setAction(new PdfAction(PdfAction.NEXTPAGE)))); table.addCell(new Phrase(new Chunk("Last Page").setAction(new PdfAction(PdfAction.LASTPAGE)))); for (int k = 1; k <= 10; ++k) { document.add(new Paragraph("This is page " + k)); document.add(Chunk.NEWLINE); document.add(table); document.add(p); document.newPage(); } // step 5: we close the document document.close(); }
Example #30
Source File: MultiColumnText.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Add an element to be rendered in a column. * Note that you can only add a <CODE>Phrase</CODE> * or a <CODE>Chunk</CODE> if the columns are * not all simple. This is an underlying restriction in * {@link com.lowagie.text.pdf.ColumnText} * * @param element element to add * @throws DocumentException if element can't be added */ public void addElement(Element element) throws DocumentException { if (simple) { columnText.addElement(element); } else if (element instanceof Phrase) { columnText.addText((Phrase) element); } else if (element instanceof Chunk) { columnText.addText((Chunk) element); } else { throw new DocumentException("Can't add " + element.getClass() + " to MultiColumnText with complex columns"); } }