Java Code Examples for com.lowagie.text.pdf.PdfPCell#setPhrase()

The following examples show how to use com.lowagie.text.pdf.PdfPCell#setPhrase() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PdfWebTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
private float addImage(PdfPCell cell, String name) {
	try {
		java.awt.Image awtImage = (java.awt.Image)iImages.get(name);
		if (awtImage==null) return 0;
		Image img = Image.getInstance(awtImage, Color.WHITE);
		Chunk ck = new Chunk(img, 0, 0);
		if (cell.getPhrase()==null) {
			cell.setPhrase(new Paragraph(ck));
			cell.setVerticalAlignment(Element.ALIGN_TOP);
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
		} else {
			cell.getPhrase().add(ck);
		}
		return awtImage.getWidth(null);
	} catch (Exception e) {
		return 0;
	}
}
 
Example 2
Source File: PdfWebTable.java    From unitime with Apache License 2.0 6 votes vote down vote up
private float addText(PdfPCell cell, String text, boolean bold, boolean italic, boolean underline, Color color, Color bgColor) {
	Font font = PdfFont.getFont(bold, italic, underline, color);
	Chunk chunk = new Chunk(text, font);
	if (bgColor!=null) chunk.setBackground(bgColor);
	if (cell.getPhrase()==null) {
	    cell.setPhrase(new Paragraph(chunk));
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	} else {
		cell.getPhrase().add(chunk);
	}
	float width = 0; 
	if (text.indexOf('\n')>=0) {
		for (StringTokenizer s = new StringTokenizer(text,"\n"); s.hasMoreTokens();)
			width = Math.max(width,font.getBaseFont().getWidthPoint(s.nextToken(), font.getSize()));
	} else 
		width = Math.max(width,font.getBaseFont().getWidthPoint(text, font.getSize()));
	return width;
}
 
Example 3
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addCell_Text( PdfPTable table, PdfPCell cell, String text, int horizontalAlignment, Font font )
{
    cell.setHorizontalAlignment( horizontalAlignment );

    cell.setPhrase( new Phrase( text, font ) );

    table.addCell( cell ); // TODO: change this with cellEvent?
}
 
Example 4
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void addText(PdfPCell cell, String text, boolean bold) {
	if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
	if (cell.getPhrase()==null) {
		cell.setPhrase(new Paragraph(text, PdfFont.getSmallFont(bold)));
		cell.setVerticalAlignment(Element.ALIGN_TOP);
		cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	} else {
		cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getSmallFont(bold)));
	}
}
 
Example 5
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void addTextVertical(PdfPCell cell, String text, boolean bold) throws Exception  {
	if (text==null) return;
       if (text.indexOf("<span")>=0)
           text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
       Font font = PdfFont.getFont(bold);
	BaseFont bf = font.getBaseFont();
	float width = bf.getWidthPoint(text, font.getSize());
	PdfTemplate template = iWriter.getDirectContent().createTemplate(2 * font.getSize() + 4, width);
	template.beginText();
	template.setColorFill(Color.BLACK);
	template.setFontAndSize(bf, font.getSize());
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(font.getSize() + 2);
	//make an Image object from the template
	Image img = Image.getInstance(template);
	img.setRotationDegrees(270);
	//embed the image in a Chunk
	Chunk ck = new Chunk(img, 0, 0);
	
	if (cell.getPhrase()==null) {
		cell.setPhrase(new Paragraph(ck));
		cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
		cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
	} else {
		cell.getPhrase().add(ck);
	}
}
 
Example 6
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public void addText(PdfPCell cell, String text, boolean bold) {
    if (text==null) return;
    if (text.indexOf("<span")>=0)
        text = text.replaceAll("</span>","").replaceAll("<span .*>", "");
    text = text.replaceAll("<br>", "\n");
    text = text.replaceAll("<BR>", "\n");
    if (cell.getPhrase()==null) {
        cell.setPhrase(new Paragraph(text, PdfFont.getFont(bold)));
        cell.setVerticalAlignment(Element.ALIGN_TOP);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    } else {
        cell.getPhrase().add(new Chunk("\n"+text, PdfFont.getFont(bold)));
    }
}
 
Example 7
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 5 votes vote down vote up
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)));
	}
}