Java Code Examples for com.lowagie.text.pdf.PdfPTable#setLockedWidth()

The following examples show how to use com.lowagie.text.pdf.PdfPTable#setLockedWidth() . 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: IncTable.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
public PdfPTable buildTable() {
	if (rows.isEmpty()) {
		return new PdfPTable(1);
	}
	int ncol = 0;
	ArrayList c0 = (ArrayList) rows.get(0);
	for (int k = 0; k < c0.size(); ++k) {
		ncol += ((PdfPCell) c0.get(k)).getColspan();
	}
	PdfPTable table = new PdfPTable(ncol);
	String width = (String) props.get("width");
	if (width == null) {
		table.setWidthPercentage(100);
	} else {
		if (width.endsWith("%")) {
			table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1)));
		} else {
			table.setTotalWidth(Float.parseFloat(width));
			table.setLockedWidth(true);
		}
	}
	for (int row = 0; row < rows.size(); ++row) {
		ArrayList col = (ArrayList) rows.get(row);
		for (int k = 0; k < col.size(); ++k) {
			table.addCell((PdfPCell) col.get(k));
		}
	}
	return table;
}
 
Example 2
Source File: IncTable.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PdfPTable buildTable() {
    if (rows.isEmpty())
        return new PdfPTable(1);
    int ncol = 0;
    ArrayList c0 = (ArrayList)rows.get(0);
    for (int k = 0; k < c0.size(); ++k) {
        ncol += ((PdfPCell)c0.get(k)).getColspan();
    }
    PdfPTable table = new PdfPTable(ncol);
    String width = (String)props.get("width");
    if (width == null)
        table.setWidthPercentage(100);
    else {
        if (width.endsWith("%"))
            table.setWidthPercentage(Float.parseFloat(width.substring(0, width.length() - 1)));
        else {
            table.setTotalWidth(Float.parseFloat(width));
            table.setLockedWidth(true);
        }
    }
    for (int row = 0; row < rows.size(); ++row) {
        ArrayList col = (ArrayList)rows.get(row);
        for (int k = 0; k < col.size(); ++k) {
            table.addCell((PdfPCell)col.get(k));
        }
    }
    return table;
}
 
Example 3
Source File: DefaultPdfDataEntryFormService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private PdfPTable getProgramStageMainTable()
{
    PdfPTable mainTable = new PdfPTable( 1 ); // Code 1

    mainTable.setTotalWidth( 800f );
    mainTable.setLockedWidth( true );
    mainTable.setHorizontalAlignment( Element.ALIGN_LEFT );

    return mainTable;
}
 
Example 4
Source File: CellWidthsTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Width manipulations of cells.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 36, 36, 36, 36);
	// step2
	PdfWriter.getInstance(document, PdfTestBase.getOutputStream("CellWidths.pdf"));
	// step3
	document.open();
	// step4
	float[] widths = { 0.1f, 0.1f, 0.05f, 0.75f };
	PdfPTable table = new PdfPTable(widths);
	table.addCell("10%");
	table.addCell("10%");
	table.addCell("5%");
	table.addCell("75%");
	table.addCell("aa");
	table.addCell("aa");
	table.addCell("a");
	table.addCell("aaaaaaaaaaaaaaa");
	table.addCell("bb");
	table.addCell("bb");
	table.addCell("b");
	table.addCell("bbbbbbbbbbbbbbb");
	table.addCell("cc");
	table.addCell("cc");
	table.addCell("c");
	table.addCell("ccccccccccccccc");
	document.add(table);
	document.add(new Paragraph("We change the percentages:\n\n"));
	widths[0] = 20f;
	widths[1] = 20f;
	widths[2] = 10f;
	widths[3] = 50f;
	table.setWidths(widths);
	document.add(table);
	widths[0] = 40f;
	widths[1] = 40f;
	widths[2] = 20f;
	widths[3] = 300f;
	Rectangle r = new Rectangle(PageSize.A4.getRight(72), PageSize.A4.getTop(72));
	table.setWidthPercentage(widths, r);
	document.add(new Paragraph("We change the percentage using absolute widths:\n\n"));
	document.add(table);
	document.add(new Paragraph("We use a locked width:\n\n"));
	table.setTotalWidth(300);
	table.setLockedWidth(true);
	document.add(table);

	// step5
	document.close();
}