Java Code Examples for com.lowagie.text.Phrase

The following examples show how to use com.lowagie.text.Phrase. These examples are extracted from open source projects. 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 Project: gcs   Author: richardwilkes   File: PdfPCell.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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 #2
Source Project: javamelody   Author: javamelody   File: PdfJndiReport.java    License: Apache License 2.0 6 votes vote down vote up
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 #3
Source Project: itext2   Author: albfernandez   File: NegativeLeadingTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #4
Source Project: javamelody   Author: javamelody   File: PdfCoreReport.java    License: Apache License 2.0 6 votes vote down vote up
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 #5
Source Project: gcs   Author: richardwilkes   File: ElementFactory.java    License: Mozilla Public License 2.0 6 votes vote down vote up
/**
 * 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 #6
Source Project: itext2   Author: albfernandez   File: DuplicateRowOnPageSplitTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #7
Source Project: pentaho-reporting   Author: pentaho   File: PdfLogicalPageDrawable.java    License: GNU Lesser General Public License v2.1 6 votes vote down vote up
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 #8
Source Project: javamelody   Author: javamelody   File: PdfRequestAndGraphDetailReport.java    License: Apache License 2.0 6 votes vote down vote up
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 Project: itext2   Author: albfernandez   File: RtfHeaderFooter.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #10
Source Project: itext2   Author: albfernandez   File: RtfHeaderFooter.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #11
Source Project: itext2   Author: albfernandez   File: ElementFactory.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #12
Source Project: itext2   Author: albfernandez   File: SymbolSubstitutionTest.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 #13
Source Project: javamelody   Author: javamelody   File: PdfDocumentFactory.java    License: Apache License 2.0 6 votes vote down vote up
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 #14
Source Project: javamelody   Author: javamelody   File: PdfCoreReport.java    License: Apache License 2.0 6 votes vote down vote up
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 #15
Source Project: DWSurvey   Author: wkeyuan   File: DocStyleUtils.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/** 
 * 功能说明:为文字填充浅灰色背景</BR> 
 * 修改日期:2011-04-27 
 * @author myclover 
 * @param content   需要填充背景颜色的内容 
 * @param appendStr 不需要填充背景颜色的内容 
 * @return 
 */  
private static Phrase setPhraseStyle(String content , String appendStr){  
    Chunk chunk = new Chunk(content);  
    //填充的背景颜色为浅灰色  
    chunk.setBackground(Color.LIGHT_GRAY);  
    Phrase phrase = new Phrase(chunk);  
    phrase.add(appendStr);  
    return phrase;  
}
 
Example #16
Source Project: DWSurvey   Author: wkeyuan   File: DocStyleUtils.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/** 
 * 功能说明:设置段落的样式,设置前半截内容和后半截内容格式不一样的段落样式</BR> 
 * 修改日:2011-04-27 
 * @author myclover 
 * @param content  前半截内容 
 * @param font     字体的样式 
 * @param firstLineIndent 首行缩进多少字符,16f约等于一个字符 
 * @param appendStr 后半截内容 
 * @return 
 */  
public static Paragraph setParagraphStyle(String content , Font font , float firstLineIndent , String appendStr){  
    Paragraph par = setParagraphStyle(content, font, 0f, 12f);  
    Phrase phrase = new Phrase();  
    phrase.add(par);  
    phrase.add(appendStr);  
    Paragraph paragraph = new Paragraph(phrase);  
    paragraph.setFirstLineIndent(firstLineIndent);  
    //设置对齐方式为两端对齐  
    paragraph.setAlignment(Paragraph.ALIGN_JUSTIFIED_ALL);  
    return paragraph;  
}
 
Example #17
Source Project: gcs   Author: richardwilkes   File: PdfPCell.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Constructs a <CODE>PdfPCell</CODE> with a <CODE>Phrase</CODE>.
 * The default padding is 2.
 * 
 * @param phrase the text
 */
public PdfPCell(Phrase phrase) {
    super(0, 0, 0, 0);
    borderWidth = 0.5f;
    border = BOX;
    column.addText(this.phrase = phrase);
    column.setLeading(0, 1);
}
 
Example #18
Source Project: gcs   Author: richardwilkes   File: ColumnText.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 #19
Source Project: gcs   Author: richardwilkes   File: ColumnText.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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 #20
Source Project: gcs   Author: richardwilkes   File: ColumnText.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Adds a <CODE>Chunk</CODE> to the current text array. Will not have any effect if addElement()
 * was called before.
 * 
 * @param chunk the text
 */
public void addText(Chunk chunk) {
	if (chunk == null || composite) {
		return;
	}
	addText(new Phrase(chunk));
}
 
Example #21
Source Project: javamelody   Author: javamelody   File: PdfSessionInformationsReport.java    License: Apache License 2.0 5 votes vote down vote up
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 #22
Source Project: MesquiteCore   Author: MesquiteProject   File: ColumnText.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/** 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(20000, Element.ALIGN_LEFT, runDirection, arabicOptions);
    if (line == null)
        return 0;
    else
        return 20000 - line.widthLeft();
}
 
Example #23
Source Project: javamelody   Author: javamelody   File: PdfCounterRequestContextReport.java    License: Apache License 2.0 5 votes vote down vote up
private void writeDurations(List<CounterRequestContext> contexts)
		throws DocumentException, IOException {
	getDefaultCell().setHorizontalAlignment(Element.ALIGN_RIGHT);

	final Paragraph paragraph = new Paragraph("", cellFont);
	boolean first = true;
	for (final CounterRequestContext context : contexts) {
		if (!first) {
			paragraph.add(new Chunk('\n', cellFont));
		}
		final int duration = context.getDuration(timeOfSnapshot);
		final Counter parentCounter = context.getParentCounter();
		final PdfCounterReport counterReport = counterReportsByCounterName
				.get(parentCounter.getName());
		if (parentCounter.getIconName() != null) {
			paragraph.add(new Chunk(getImage(parentCounter.getIconName()), 0, -1));
		}
		final Font slaFont;
		if (counterReport == null) {
			slaFont = infoCellFont;
		} else {
			slaFont = counterReport.getSlaFont(duration);
		}
		paragraph.add(new Phrase(integerFormat.format(duration), slaFont));
		first = false;
	}
	addCell(paragraph);
}
 
Example #24
Source Project: javamelody   Author: javamelody   File: PdfRequestAndGraphDetailReport.java    License: Apache License 2.0 5 votes vote down vote up
private void writeRequest(CounterRequest childRequest, float executionsByRequest,
		boolean allChildHitsDisplayed) throws IOException, DocumentException {
	final PdfPCell defaultCell = getDefaultCell();
	defaultCell.setHorizontalAlignment(Element.ALIGN_LEFT);
	final Paragraph paragraph = new Paragraph(defaultCell.getLeading() + cellFont.getSize());
	if (executionsByRequest != -1) {
		paragraph.setIndentationLeft(5);
	}
	final Counter parentCounter = getCounterByRequestId(childRequest);
	if (parentCounter != null && parentCounter.getIconName() != null) {
		paragraph.add(new Chunk(getSmallImage(parentCounter.getIconName()), 0, -1));
	}
	paragraph.add(new Phrase(childRequest.getName(), cellFont));
	final PdfPCell requestCell = new PdfPCell();
	requestCell.addElement(paragraph);
	requestCell.setGrayFill(defaultCell.getGrayFill());
	requestCell.setPaddingTop(defaultCell.getPaddingTop());
	addCell(requestCell);

	defaultCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	if (executionsByRequest != -1) {
		addCell(nbExecutionsFormat.format(executionsByRequest));
	} else {
		final boolean hasChildren = !request.getChildRequestsExecutionsByRequestId().isEmpty();
		if (hasChildren) {
			addCell("");
		}
	}
	writeRequestValues(childRequest, allChildHitsDisplayed);
}
 
Example #25
Source Project: gcs   Author: richardwilkes   File: MultiColumnText.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/**
 * 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");
	}
}
 
Example #26
Source Project: gcs   Author: richardwilkes   File: IncCell.java    License: Mozilla Public License 2.0 5 votes vote down vote up
/** 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 #27
Source Project: itext2   Author: albfernandez   File: PdfPCell.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructs a <CODE>PdfPCell</CODE> with a <CODE>Phrase</CODE>.
 * The default padding is 2.
 * 
 * @param phrase the text
 */
public PdfPCell(Phrase phrase) {
    super(0, 0, 0, 0);
    borderWidth = 0.5f;
    border = BOX;
    column.addText(this.phrase = phrase);
    column.setLeading(0, 1);
}
 
Example #28
Source Project: javamelody   Author: javamelody   File: PdfSessionInformationsReport.java    License: Apache License 2.0 5 votes vote down vote up
@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 #29
Source Project: javamelody   Author: javamelody   File: PdfJavaInformationsReport.java    License: Apache License 2.0 5 votes vote down vote up
private void writeServerInfo(String serverInfo) throws BadElementException, IOException {
	addCell(getString("Serveur") + ':');
	final Phrase serverInfoPhrase = new Phrase("", cellFont);
	final String applicationServerIconName = HtmlJavaInformationsReport
			.getApplicationServerIconName(serverInfo);
	if (applicationServerIconName != null) {
		final Image applicationServerImage = PdfDocumentFactory
				.getImage("servers/" + applicationServerIconName);
		applicationServerImage.scalePercent(40);
		serverInfoPhrase.add(new Chunk(applicationServerImage, 0, 0));
		serverInfoPhrase.add(new Chunk("   "));
	}
	serverInfoPhrase.add(new Chunk(serverInfo));
	currentTable.addCell(serverInfoPhrase);
}
 
Example #30
Source Project: itext2   Author: albfernandez   File: ColumnText.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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));
    }
}