com.lowagie.text.Phrase Java Examples
The following examples show how to use
com.lowagie.text.Phrase.
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: OptionalContentTest.java From itext2 with GNU Lesser General Public License v3.0 | 7 votes |
/** * Demonstrates the use of layers. * * @param args * no arguments needed */ @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: creation of the writer PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("optionalcontent.pdf")); writer.setPdfVersion(PdfWriter.VERSION_1_5); writer.setViewerPreferences(PdfWriter.PageModeUseOC); // step 3: opening the document document.open(); // step 4: content PdfContentByte cb = writer.getDirectContent(); Phrase explanation = new Phrase( "Automatic layers, form fields, images, templates and actions", new Font(Font.HELVETICA, 18, Font.BOLD, Color.red)); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, explanation, 50, 650, 0); PdfLayer l1 = new PdfLayer("Layer 1", writer); PdfLayer l2 = new PdfLayer("Layer 2", writer); PdfLayer l3 = new PdfLayer("Layer 3", writer); PdfLayer l4 = new PdfLayer("Form and XObject Layer", writer); PdfLayerMembership m1 = new PdfLayerMembership(writer); m1.addMember(l2); m1.addMember(l3); Phrase p1 = new Phrase("Text in layer 1"); Phrase p2 = new Phrase("Text in layer 2 or layer 3"); Phrase p3 = new Phrase("Text in layer 3"); cb.beginLayer(l1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p1, 50, 600, 0f); cb.endLayer(); cb.beginLayer(m1); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p2, 50, 550, 0); cb.endLayer(); cb.beginLayer(l3); ColumnText.showTextAligned(cb, Element.ALIGN_LEFT, p3, 50, 500, 0); cb.endLayer(); TextField ff = new TextField(writer, new Rectangle(200, 600, 300, 620), "field1"); ff.setBorderColor(Color.blue); ff.setBorderStyle(PdfBorderDictionary.STYLE_SOLID); ff.setBorderWidth(TextField.BORDER_WIDTH_THIN); ff.setText("I'm a form field"); PdfFormField form = ff.getTextField(); form.setLayer(l4); writer.addAnnotation(form); Image img = Image.getInstance(PdfTestBase.RESOURCES_DIR + "pngnow.png"); img.setLayer(l4); img.setAbsolutePosition(200, 550); cb.addImage(img); PdfTemplate tp = cb.createTemplate(100, 20); Phrase pt = new Phrase("I'm a template", new Font(Font.HELVETICA, 12, Font.NORMAL, Color.magenta)); ColumnText.showTextAligned(tp, Element.ALIGN_LEFT, pt, 0, 0, 0); tp.setLayer(l4); tp.setBoundingBox(new Rectangle(0, -10, 100, 20)); cb.addTemplate(tp, 200, 500); ArrayList<Object> state = new ArrayList<Object>(); state.add("toggle"); state.add(l1); state.add(l2); state.add(l3); state.add(l4); PdfAction action = PdfAction.setOCGstate(state, true); Chunk ck = new Chunk("Click here to toggle the layers", new Font( Font.HELVETICA, 18, Font.NORMAL, Color.yellow)).setBackground( Color.blue).setAction(action); ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, new Phrase(ck), 250, 400, 0); cb.sanityCheck(); // step 5: closing the document document.close(); }
Example #2
Source File: ElementFactory.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Creates a Phrase object based on a list of properties. * * @param attributes * @return a Phrase */ public static Phrase getPhrase(Properties attributes) { Phrase phrase = new Phrase(); phrase.setFont(FontFactory.getFont(attributes)); String value; value = attributes.getProperty(ElementTags.LEADING); if (value != null) { phrase.setLeading(Float.parseFloat(value + "f")); } value = attributes.getProperty(Markup.CSS_KEY_LINEHEIGHT); if (value != null) { phrase.setLeading(Markup.parseLength(value, Markup.DEFAULT_FONT_SIZE)); } value = attributes.getProperty(ElementTags.ITEXT); if (value != null) { Chunk chunk = new Chunk(value); if ((value = attributes.getProperty(ElementTags.GENERICTAG)) != null) { chunk.setGenericTag(value); } phrase.add(chunk); } return phrase; }
Example #3
Source File: SymbolSubstitutionTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * How to substiture special characters with Phrase.getInstance. */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SymbolSubstitution.pdf")); // step 3: we open the document document.open(); // step 4: document.add(Phrase.getInstance("What is the " + (char) 945 + "-coefficient of the " + (char) 946 + "-factor in the " + (char) 947 + "-equation?\n")); for (int i = 913; i < 970; i++) { document.add(Phrase.getInstance(" " + i + ": " + (char) i)); } // step 5: we close the document document.close(); }
Example #4
Source File: PdfCoreReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeJCaches(boolean includeDetails) throws DocumentException { String eol = ""; if (isCacheEnabled()) { // new line in case there are both cache and jcache eol = "\n"; } for (final JavaInformations javaInformations : javaInformationsList) { if (!javaInformations.isJCacheEnabled()) { continue; } final List<JCacheInformations> jcacheInformationsList = javaInformations .getJCacheInformationsList(); final String msg = getFormattedString("caches_sur", jcacheInformationsList.size(), javaInformations.getHost()); addToDocument(new Phrase(eol + msg, boldFont)); if (includeDetails) { new PdfJCacheInformationsReport(jcacheInformationsList, getDocument()).toPdf(); } eol = "\n"; } }
Example #5
Source File: PdfCoreReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeJobs(Counter rangeJobCounter, boolean includeDetails) throws DocumentException, IOException { String eol = ""; for (final JavaInformations javaInformations : javaInformationsList) { if (!javaInformations.isJobEnabled()) { continue; } final List<JobInformations> jobInformationsList = javaInformations .getJobInformationsList(); final String msg = getFormattedString("jobs_sur", jobInformationsList.size(), javaInformations.getHost(), javaInformations.getCurrentlyExecutingJobCount()); addToDocument(new Phrase(eol + msg, boldFont)); if (includeDetails) { new PdfJobInformationsReport(jobInformationsList, rangeJobCounter, getDocument()) .toPdf(); } eol = "\n"; } }
Example #6
Source File: PdfLogicalPageDrawable.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
protected void drawComplexText( final RenderableComplexText node, final Graphics2D g2 ) { try { final Phrase p = createPhrase( node ); final ColumnConfig cc = createColumnText( node ); final PdfGraphics2D pg2 = (PdfGraphics2D) getGraphics(); final PdfContentByte cb = pg2.getRawContentByte(); ColumnText ct = cc.reconfigure( cb, p ); ct.setText( p ); if ( ct.go( false ) == ColumnText.NO_MORE_COLUMN ) { throw new InvalidReportStateException( "iText signaled an error when printing text. Failing to prevent silent data-loss: Width=" + ct.getFilledWidth() ); } } catch ( DocumentException e ) { throw new InvalidReportStateException( e ); } }
Example #7
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 #8
Source File: PdfRequestAndGraphDetailReport.java From javamelody with Apache License 2.0 | 6 votes |
private void writeGraph() throws IOException, DocumentException { final JRobin jrobin = collector.getJRobin(graphName); if (jrobin != null) { final byte[] img = jrobin.graph(range, 960, 400); final Image image = Image.getInstance(img); image.scalePercent(50); final PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell("\n"); table.addCell(image); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT); table.addCell(new Phrase(getString("graph_units"), cellFont)); addToDocument(table); } else { // just in case request is null and collector.getJRobin(graphName) is null, we must write something in the document addToDocument(new Phrase("\n", cellFont)); } }
Example #9
Source File: PdfDocumentFactory.java From javamelody with Apache License 2.0 | 6 votes |
private void createWriter(Document document, String title) throws DocumentException, IOException { final PdfWriter writer = PdfWriter.getInstance(document, output); //writer.setViewerPreferences(PdfWriter.PageLayoutTwoColumnLeft); // title final HeaderFooter header = new HeaderFooter(new Phrase(title), false); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); // simple page numbers : x //HeaderFooter footer = new HeaderFooter(new Phrase(), true); //footer.setAlignment(Element.ALIGN_RIGHT); //footer.setBorder(Rectangle.TOP); //document.setFooter(footer); // add the event handler for advanced page numbers : x/y writer.setPageEvent(new PdfAdvancedPageNumberEvents()); }
Example #10
Source File: NegativeLeadingTest.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Demonstrates what happens if you choose a negative leading. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("NegativeLeading.pdf")); // step 3: we open the document document.open(); // step 4: document.add(new Phrase(16, "\n\n\n")); document.add(new Phrase( -16, "Hello, this is a very long phrase to show you the somewhat odd effect of a negative leading. You can write from bottom to top. This is not fully supported. It's something between a feature and a bug.")); // step 5: we close the document document.close(); }
Example #11
Source File: PdfPCell.java From gcs with Mozilla Public License 2.0 | 6 votes |
/** * Constructs a <CODE>PdfPCell</CODE> with an <CODE>Image</CODE>. * The default padding is 0.25 for a border width of 0.5. * * @param image the <CODE>Image</CODE> * @param fit <CODE>true</CODE> to fit the image to the cell */ public PdfPCell(Image image, boolean fit) { super(0, 0, 0, 0); borderWidth = 0.5f; border = BOX; if (fit) { this.image = image; column.setLeading(0, 1); setPadding(borderWidth / 2); } else { column.addText(this.phrase = new Phrase(new Chunk(image, 0, 0))); column.setLeading(0, 1); setPadding(0); } }
Example #12
Source File: RtfHeaderFooter.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Constructs a RtfHeaderFooter as a copy of an existing RtfHeaderFooter. * For internal use only. * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The RtfHeaderFooter to copy * @param displayAt The display location of this RtfHeaderFooter */ protected RtfHeaderFooter(RtfDocument doc, RtfHeaderFooter headerFooter, int displayAt) { super(new Phrase(""), false); this.document = doc; this.content = headerFooter.getContent(); this.displayAt = displayAt; for(int i = 0; i < this.content.length; i++) { if(this.content[i] instanceof Element) { try { this.content[i] = this.document.getMapper().mapElement((Element) this.content[i])[0]; } catch(DocumentException de) { de.printStackTrace(); } } if(this.content[i] instanceof RtfBasicElement) { ((RtfBasicElement) this.content[i]).setInHeader(true); } } }
Example #13
Source File: RtfHeaderFooter.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Constructs a RtfHeaderFooter for a HeaderFooter. * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The HeaderFooter to base this RtfHeaderFooter on */ protected RtfHeaderFooter(RtfDocument doc, HeaderFooter headerFooter) { super(new Phrase(""), false); this.document = doc; Paragraph par = new Paragraph(); par.setAlignment(headerFooter.alignment()); if (headerFooter.getBefore() != null) { par.add(headerFooter.getBefore()); } if (headerFooter.isNumbered()) { par.add(new RtfPageNumber(this.document)); } if (headerFooter.getAfter() != null) { par.add(headerFooter.getAfter()); } try { this.content = new Object[1]; this.content[0] = doc.getMapper().mapElement(par)[0]; ((RtfBasicElement) this.content[0]).setInHeader(true); } catch(DocumentException de) { de.printStackTrace(); } }
Example #14
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 #15
Source File: ElementFactory.java From itext2 with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a Phrase object based on a list of properties. * @param attributes * @return a Phrase */ public static Phrase getPhrase(Properties attributes) { Phrase phrase = new Phrase(); phrase.setFont(FontFactory.getFont(attributes)); String value; value = attributes.getProperty(ElementTags.LEADING); if (value != null) { phrase.setLeading(Float.parseFloat(value + "f")); } value = attributes.getProperty(Markup.CSS_KEY_LINEHEIGHT); if (value != null) { phrase.setLeading(Markup.parseLength(value, Markup.DEFAULT_FONT_SIZE)); } value = attributes.getProperty(ElementTags.ITEXT); if (value != null) { Chunk chunk = new Chunk(value); if ((value = attributes.getProperty(ElementTags.GENERICTAG)) != null) { chunk.setGenericTag(value); } phrase.add(chunk); } return phrase; }
Example #16
Source File: MRtfWriter.java From javamelody with Apache License 2.0 | 5 votes |
/** * We create a writer that listens to the document and directs a RTF-stream to out * * @param table * MBasicTable * @param document * Document * @param out * OutputStream * @return DocWriter */ @Override protected DocWriter createWriter(final MBasicTable table, final Document document, final OutputStream out) { final RtfWriter2 writer = RtfWriter2.getInstance(document, out); // title final String title = buildTitle(table); if (title != null) { final HeaderFooter header = new RtfHeaderFooter(new Paragraph(title)); header.setAlignment(Element.ALIGN_LEFT); header.setBorder(Rectangle.NO_BORDER); document.setHeader(header); document.addTitle(title); } // advanced page numbers : x/y final Paragraph footerParagraph = new Paragraph(); final Font font = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.NORMAL); footerParagraph.add(new RtfPageNumber(font)); footerParagraph.add(new Phrase(" / ", font)); footerParagraph.add(new RtfTotalPageNumber(font)); footerParagraph.setAlignment(Element.ALIGN_CENTER); final HeaderFooter footer = new RtfHeaderFooter(footerParagraph); footer.setBorder(Rectangle.TOP); document.setFooter(footer); return writer; }
Example #17
Source File: PdfThreadInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeThreadInformations(ThreadInformations threadInformations) throws DocumentException, IOException { final PdfPCell defaultCell = getDefaultCell(); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); addCell(threadInformations.getName()); defaultCell.setHorizontalAlignment(Element.ALIGN_CENTER); if (threadInformations.isDaemon()) { addCell(getString("oui")); } else { addCell(getString("non")); } defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(threadInformations.getPriority())); defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT); final PdfPCell cell = new PdfPCell(); final Paragraph paragraph = new Paragraph( getDefaultCell().getLeading() + cellFont.getSize()); paragraph.add(new Chunk( getImage( "bullets/" + HtmlThreadInformationsReport.getStateIcon(threadInformations)), 0, -1)); paragraph.add(new Phrase(String.valueOf(threadInformations.getState()), cellFont)); cell.addElement(paragraph); addCell(cell); if (stackTraceEnabled) { addCell(threadInformations.getExecutedMethod()); } if (cpuTimeEnabled) { defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT); addCell(integerFormat.format(threadInformations.getCpuTimeMillis())); addCell(integerFormat.format(threadInformations.getUserTimeMillis())); } }
Example #18
Source File: FontFactoryStylesTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Changing the style of a FontFactory Font. * * @param args * no arguments needed */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: creation of the writer PdfWriter.getInstance(document, PdfTestBase.getOutputStream("fontfactorystyles.pdf")); // step 3: we open the document document.open(); String fontPathBase = new File(PdfTestBase.RESOURCES_DIR + "liberation-fonts-ttf").getAbsolutePath(); // step 4: we add some content FontFactory.register(fontPathBase + "/LiberationSans-Regular.ttf"); FontFactory.register(fontPathBase + "/LiberationSans-Italic.ttf"); FontFactory.register(fontPathBase + "/LiberationSans-Bold.ttf"); FontFactory.register(fontPathBase + "/LiberationSans-BoldItalic.ttf"); Phrase myPhrase = new Phrase("This is font family Liberation Sans ", FontFactory.getFont("LiberationSans", 8)); myPhrase.add(new Phrase("italic ", FontFactory.getFont("Arial", 8, Font.ITALIC))); myPhrase.add(new Phrase("bold ", FontFactory.getFont("Arial", 8, Font.BOLD))); myPhrase.add(new Phrase("bolditalic", FontFactory.getFont("Arial", 8, Font.BOLDITALIC))); document.add(myPhrase); // step 5: we close the document document.close(); }
Example #19
Source File: Coversheet.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Creates mailTo section for the coversheet. The MailTo section is where the coversheet will be mailed. * * @returns a {@link Paragraph} for the PDF */ protected Paragraph getMailtoParagraph() { final Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD); final Font normalFont = FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL); final Paragraph retval = new Paragraph(); retval.add(new Chunk("Mail coversheet to:", headerFont)); retval.add(Chunk.NEWLINE); retval.add(new Phrase(getMailTo(), normalFont)); return retval; }
Example #20
Source File: ColumnText.java From MesquiteCore with GNU Lesser General Public License v3.0 | 5 votes |
/** * Replaces the current text array with this <CODE>Phrase</CODE>. * Anything added previously with addElement() is lost. * @param phrase the text */ public void setText(Phrase phrase) { bidiLine = null; composite = false; compositeColumn = null; compositeElements = null; listIdx = 0; splittedRow = false; waitPhrase = phrase; }
Example #21
Source File: PdfCounterReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeNoRequests() throws DocumentException { final String msg; if (isJobCounter()) { msg = "Aucun_job"; } else if (isErrorCounter()) { msg = "Aucune_erreur"; } else { msg = "Aucune_requete"; } addToDocument(new Phrase(getString(msg), normalFont)); }
Example #22
Source File: RtfPhrase.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Constructs a new RtfPhrase for the RtfDocument with the given Phrase * * @param doc The RtfDocument this RtfPhrase belongs to * @param phrase The Phrase this RtfPhrase is based on */ public RtfPhrase(RtfDocument doc, Phrase phrase) { super(doc); if(phrase == null) { return; } if(phrase.hasLeading()) { this.lineLeading = (int) (phrase.getLeading() * RtfElement.TWIPS_FACTOR); } else { this.lineLeading = 0; } RtfFont phraseFont = new RtfFont(null, phrase.getFont()); for(int i = 0; i < phrase.size(); i++) { Element chunk = (Element) phrase.get(i); if(chunk instanceof Chunk) { ((Chunk) chunk).setFont(phraseFont.difference(((Chunk) chunk).getFont())); } try { RtfBasicElement[] rtfElements = doc.getMapper().mapElement(chunk); for(int j = 0; j < rtfElements.length; j++) { chunks.add(rtfElements[j]); } } catch(DocumentException de) { } } }
Example #23
Source File: IncCell.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** Creates a new instance of IncCell */ public IncCell(String tag, ChainedProperties props) { cell = new PdfPCell((Phrase)null); String value = props.getProperty("colspan"); if (value != null) cell.setColspan(Integer.parseInt(value)); value = props.getProperty("align"); if (tag.equals("th")) cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (value != null) { if ("center".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_CENTER); else if ("right".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_RIGHT); else if ("left".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_LEFT); else if ("justify".equalsIgnoreCase(value)) cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); } value = props.getProperty("valign"); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); if (value != null) { if ("top".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_TOP); else if ("bottom".equalsIgnoreCase(value)) cell.setVerticalAlignment(Element.ALIGN_BOTTOM); } value = props.getProperty("border"); float border = 0; if (value != null) border = Float.parseFloat(value); cell.setBorderWidth(border); value = props.getProperty("cellpadding"); if (value != null) cell.setPadding(Float.parseFloat(value)); cell.setUseDescender(true); value = props.getProperty("bgcolor"); cell.setBackgroundColor(Markup.decodeColor(value)); }
Example #24
Source File: RtfHeaderFooterGroup.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Constructs a RtfHeaderFooterGroup for a certain RtfHeaderFooter. * * @param doc The RtfDocument this RtfHeaderFooter belongs to * @param headerFooter The RtfHeaderFooter to display * @param type The type of RtfHeaderFooterGroup to create */ public RtfHeaderFooterGroup(RtfDocument doc, RtfHeaderFooter headerFooter, int type) { super(new Phrase(""), false); this.document = doc; this.type = type; this.mode = MODE_SINGLE; headerAll = new RtfHeaderFooter(doc, headerFooter, RtfHeaderFooter.DISPLAY_ALL_PAGES); headerAll.setType(this.type); }
Example #25
Source File: PdfJavaInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeFileDescriptorCounts(JavaInformations javaInformations) throws BadElementException, IOException { final long unixOpenFileDescriptorCount = javaInformations.getUnixOpenFileDescriptorCount(); final long unixMaxFileDescriptorCount = javaInformations.getUnixMaxFileDescriptorCount(); addCell(getString("nb_fichiers") + ':'); final Phrase fileDescriptorCountPhrase = new Phrase( integerFormat.format(unixOpenFileDescriptorCount) + DIVIDE + integerFormat.format(unixMaxFileDescriptorCount) + BAR_SEPARATOR, cellFont); final Image fileDescriptorCountImage = Image.getInstance( Bar.toBarWithAlert(javaInformations.getUnixOpenFileDescriptorPercentage()), null); fileDescriptorCountImage.scalePercent(50); fileDescriptorCountPhrase.add(new Chunk(fileDescriptorCountImage, 0, 0)); currentTable.addCell(fileDescriptorCountPhrase); }
Example #26
Source File: PdfSessionInformationsReport.java From javamelody with Apache License 2.0 | 5 votes |
@Override void toPdf() throws IOException, DocumentException { if (sessionsInformations.isEmpty()) { addToDocument(new Phrase(getString("Aucune_session"), cellFont)); return; } writeHeader(); writeSessions(); long totalSerializedSize = 0; int nbSerializableSessions = 0; for (final SessionInformations sessionInformations : sessionsInformations) { final int size = sessionInformations.getSerializedSize(); if (size >= 0) { totalSerializedSize += size; nbSerializableSessions++; } } final long meanSerializedSize; if (nbSerializableSessions > 0) { meanSerializedSize = totalSerializedSize / nbSerializableSessions; } else { meanSerializedSize = -1; } final Paragraph paragraph = new Paragraph("", cellFont); paragraph.add(new Chunk(getFormattedString("nb_sessions", sessionsInformations.size()) + "\n\n" + getFormattedString("taille_moyenne_sessions", meanSerializedSize))); paragraph.setAlignment(Element.ALIGN_RIGHT); addToDocument(paragraph); }
Example #27
Source File: ColumnText.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the width that the line will occupy after writing. * Only the width of the first line is returned. * * @param phrase the <CODE>Phrase</CODE> containing the line * @param runDirection the run direction * @param arabicOptions the options for the arabic shaping * @return the width of the line */ public static float getWidth(Phrase phrase, int runDirection, int arabicOptions) { ColumnText ct = new ColumnText(null); ct.addText(phrase); ct.addWaitingPhrase(); PdfLine line = ct.bidiLine.processLine(0, 20000, Element.ALIGN_LEFT, runDirection, arabicOptions); if (line == null) return 0; else return 20000 - line.widthLeft(); }
Example #28
Source File: ColumnText.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Adds a <CODE>Phrase</CODE> to the current text array. * Will not have any effect if addElement() was called before. * * @param phrase the text */ public void addText(Phrase phrase) { if (phrase == null || composite) return; addWaitingPhrase(); if (bidiLine == null) { waitPhrase = phrase; return; } for (Iterator j = phrase.getChunks().iterator(); j.hasNext();) { bidiLine.addChunk(new PdfChunk((Chunk)j.next(), null)); } }
Example #29
Source File: PdfCoreReport.java From javamelody with Apache License 2.0 | 5 votes |
private void writeCurrentRequestsDetails( List<PdfCounterRequestContextReport> pdfCounterRequestContextReports) throws IOException, DocumentException { for (final PdfCounterRequestContextReport pdfCounterRequestContextReport : pdfCounterRequestContextReports) { pdfCounterRequestContextReport.writeContextDetails(); } if (pdfCounterRequestContextReports.isEmpty()) { addToDocument(new Phrase(getString("Aucune_requete_en_cours"), normalFont)); } }
Example #30
Source File: ParagraphsTest.java From itext2 with GNU Lesser General Public License v3.0 | 5 votes |
/** * Demonstrates some Paragraph functionality. * */ @Test public void main() throws Exception { // step 1: creation of a document-object Document document = new Document(); // step 2: // we create a writer that listens to the document PdfWriter.getInstance(document, PdfTestBase.getOutputStream("Paragraphs.pdf")); // step 3: we open the document document.open(); // step 4: Paragraph p1 = new Paragraph(new Chunk("This is my first paragraph. ", FontFactory.getFont( FontFactory.HELVETICA, 10))); p1.add("The leading of this paragraph is calculated automagically. "); p1.add("The default leading is 1.5 times the fontsize. "); p1.add(new Chunk("You can add chunks ")); p1.add(new Phrase("or you can add phrases. ")); p1.add(new Phrase( "Unless you change the leading with the method setLeading, the leading doesn't change if you add text with another leading. This can lead to some problems.", FontFactory.getFont(FontFactory.HELVETICA, 18))); document.add(p1); Paragraph p2 = new Paragraph(new Phrase("This is my second paragraph. ", FontFactory.getFont( FontFactory.HELVETICA, 12))); p2.add("As you can see, it started on a new line."); document.add(p2); Paragraph p3 = new Paragraph("This is my third paragraph.", FontFactory.getFont(FontFactory.HELVETICA, 12)); document.add(p3); // step 5: we close the document document.close(); }