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

The following examples show how to use com.lowagie.text.pdf.PdfPCell#setPadding() . 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: TableBordersTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static PdfPCell makeCell(String text, int vAlignment, int hAlignment, Font font, float leading,
		float padding, Rectangle borders, boolean ascender, boolean descender) {
	Paragraph p = new Paragraph(text, font);
	p.setLeading(leading);

	PdfPCell cell = new PdfPCell(p);
	cell.setLeading(leading, 0);
	cell.setVerticalAlignment(vAlignment);
	cell.setHorizontalAlignment(hAlignment);
	cell.cloneNonPositionParameters(borders);
	cell.setUseAscender(ascender);
	cell.setUseDescender(descender);
	cell.setUseBorderPadding(true);
	cell.setPadding(padding);
	return cell;
}
 
Example 2
Source File: IncCell.java    From gcs with 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 3
Source File: IncCell.java    From itext2 with GNU Lesser General Public License v3.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 4
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
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.setBorderWidthTop(1);
	cell.setBorderWidthBottom(1);
	cell.setBorderWidthLeft(1);
	cell.setBorderWidthRight(1);
	return cell;
}
 
Example 5
Source File: PdfTimetableGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public PdfPCell createCellNoBorder() {
	PdfPCell cell = new PdfPCell();
	cell.setBorderColor(sBorderColor);
	cell.setPadding(3);
	cell.setBorderWidth(0);
	cell.setVerticalAlignment(Element.ALIGN_TOP);
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	return cell;
}
 
Example 6
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
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.setBorderWidthTop(1);
    cell.setBorderWidthBottom(1);
    cell.setBorderWidthLeft(1);
    cell.setBorderWidthRight(1);
    return cell;
}
 
Example 7
Source File: PdfExamGridTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
public PdfPCell createCellNoBorder() {
    PdfPCell cell = new PdfPCell();
    cell.setBorderColor(sBorderColor);
    cell.setPadding(3);
    cell.setBorderWidth(0);
    cell.setVerticalAlignment(Element.ALIGN_TOP);
    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
    return cell;
}
 
Example 8
Source File: PdfInstructionalOfferingTableBuilder.java    From unitime with Apache License 2.0 5 votes vote down vote up
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 9
Source File: PdfWebTable.java    From unitime with Apache License 2.0 5 votes vote down vote up
private PdfPCell createCell() {
	PdfPCell cell = new PdfPCell();
	cell.setBorderColor(Color.BLACK);
	cell.setPadding(3);
	cell.setBorderWidth(0);
	cell.setVerticalAlignment(Element.ALIGN_TOP);
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	return cell;
}
 
Example 10
Source File: TemplateImagesTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
    * PdfTemplates can be wrapped in an Image.
    */
@Test
   public  void main() throws Exception {
       
           
       // step 1: creation of a document-object
       Rectangle rect = new Rectangle(PageSize.A4);
       rect.setBackgroundColor(new Color(238, 221, 88));
       Document document = new Document(rect, 50, 50, 50, 50);
	// step 2: we create a writer that listens to the document
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("templateImages.pdf"));
	// step 3: we open the document
	document.open();
	// step 4:
	PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
	BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI,
			BaseFont.NOT_EMBEDDED);
	String text = "Vertical";
	float size = 16;
	float width = bf.getWidthPoint(text, size);
	template.beginText();
	template.setRGBColorFillF(1, 1, 1);
	template.setFontAndSize(bf, size);
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(size + 2);
	template.sanityCheck();
	Image img = Image.getInstance(template);
	img.setRotationDegrees(90);
	Chunk ck = new Chunk(img, 0, 0);
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	PdfPCell cell = new PdfPCell(img);
	cell.setPadding(4);
	cell.setBackgroundColor(new Color(0, 0, 255));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	table.addCell(cell);
	table.addCell("I see a template everywhere");
	table.addCell(cell);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");

	Paragraph p1 = new Paragraph("This is a template ");
	p1.add(ck);
	p1.add(" just here.");
	p1.setLeading(img.getScaledHeight() * 1.1f);
	document.add(p1);
	document.add(table);
	Paragraph p2 = new Paragraph("More templates ");
	p2.setLeading(img.getScaledHeight() * 1.1f);
	p2.setAlignment(Element.ALIGN_JUSTIFIED);
	img.scalePercent(70);
	for (int k = 0; k < 20; ++k)
		p2.add(ck);
	document.add(p2);
	// step 5: we close the document
	document.close();

   }
 
Example 11
Source File: VerticalTextInCellsTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Example with vertical text in Cells.
 */
@Test
public void main() throws Exception {

	// step1
	Document document = new Document(PageSize.A4, 50, 50, 50, 50);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("VerticalText.pdf"));
	// step3
	document.open();
	// step4

	// make a PdfTemplate with the vertical text
	PdfTemplate template = writer.getDirectContent().createTemplate(20, 20);
	BaseFont bf = BaseFont.createFont("Helvetica", "winansi", false);
	String text = "Vertical";
	float size = 16;
	float width = bf.getWidthPoint(text, size);
	template.beginText();
	template.setRGBColorFillF(1, 1, 1);
	template.setFontAndSize(bf, size);
	template.setTextMatrix(0, 2);
	template.showText(text);
	template.endText();
	template.setWidth(width);
	template.setHeight(size + 2);
	// make an Image object from the template
	Image img = Image.getInstance(template);
	img.setRotationDegrees(90);
	PdfPTable table = new PdfPTable(3);
	table.setWidthPercentage(100);
	table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
	table.getDefaultCell().setVerticalAlignment(Element.ALIGN_MIDDLE);
	PdfPCell cell = new PdfPCell(img);
	cell.setPadding(4);
	cell.setBackgroundColor(new Color(0, 0, 255));
	cell.setHorizontalAlignment(Element.ALIGN_CENTER);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	table.addCell(cell);
	table.addCell("I see a template everywhere");
	table.addCell(cell);
	table.addCell("I see a template on my right");
	table.addCell(cell);
	table.addCell("I see a template on my left");
	document.add(table);

	// step5
	document.close();
}
 
Example 12
Source File: PdfDataEntryFormUtil.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static PdfPCell getPdfPCell( float minHeight, int cellContentType, boolean hasBorder )
{
    PdfPCell cell = new PdfPCell();
    cell.setMinimumHeight( minHeight );
    
    if( hasBorder )
    {
        cell.setBorderWidth( 0.1f );
        cell.setBorderColor( COLOR_CELLBORDER );            
    }
    else
    {
        cell.setBorder( Rectangle.NO_BORDER );
    }
    
    cell.setPadding( 2.0f );

    switch ( cellContentType )
    {
        case CELL_COLUMN_TYPE_ENTRYFIELD:
            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
            cell.setVerticalAlignment( Element.ALIGN_MIDDLE );

            break;

        case CELL_COLUMN_TYPE_HEADER:
            cell.setHorizontalAlignment( Element.ALIGN_CENTER );
            cell.setVerticalAlignment( Element.ALIGN_MIDDLE );

            break;

        case CELL_COLUMN_TYPE_LABEL:
            cell.setHorizontalAlignment( Element.ALIGN_RIGHT );
            cell.setVerticalAlignment( Element.ALIGN_TOP );

        default:
            break;
    }

    return cell;
}