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

The following examples show how to use com.lowagie.text.pdf.PdfPTable#writeSelectedRows() . 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: SplitTableTest.java    From itext2 with GNU Lesser General Public License v3.0 8 votes vote down vote up
/**
 * Break a large table up into several smaller tables for memory management
 * purposes.
 * 
 */
@Test
public void main() throws Exception {
	// step1
	Document document = new Document(PageSize.A4, 10, 10, 10, 10);
	// step2
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("SplitTable.pdf"));
	// step3
	document.open();
	// step4

	PdfContentByte cb = writer.getDirectContent();
	PdfPTable table = new PdfPTable(10);
	for (int k = 1; k <= 100; ++k) {
		table.addCell("The number " + k);
	}
	table.setTotalWidth(800);
	table.writeSelectedRows(0, 5, 0, -1, 50, 650, cb);
	document.newPage();
	table.writeSelectedRows(5, -1, 0, -1, 50, 650, cb);
	document.close();

	// step5
	document.close();
}
 
Example 2
Source File: EndPageTest.java    From itext2 with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter,
 *      com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
	try {
		Rectangle page = document.getPageSize();
		PdfPTable head = new PdfPTable(3);
		for (int k = 1; k <= 6; ++k)
			head.addCell("head " + k);
		head.setTotalWidth(page.getWidth() - document.leftMargin()
				- document.rightMargin());
		head.writeSelectedRows(
				0,
				-1,
				document.leftMargin(),
				page.getHeight() - document.topMargin()
						+ head.getTotalHeight(), writer.getDirectContent());
		PdfPTable foot = new PdfPTable(3);
		for (int k = 1; k <= 6; ++k)
			foot.addCell("foot " + k);
		foot.setTotalWidth(page.getWidth() - document.leftMargin()
				- document.rightMargin());
		foot.writeSelectedRows(0, -1, document.leftMargin(),
				document.bottomMargin(), writer.getDirectContent());
	} catch (Exception e) {
		throw new ExceptionConverter(e);
	}
}
 
Example 3
Source File: CellEventsTest.java    From itext2 with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * General example using cell events.
 * 
 */
@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("CellEvents.pdf"));
	// step3
	document.open();
	// step4
	CellEventsTest event = new CellEventsTest();
	Image im = Image.getInstance(PdfTestBase.RESOURCES_DIR + "otsoe.jpg");
	im.setRotationDegrees(30);
	PdfPTable table = new PdfPTable(4);
	table.addCell("text 1");
	PdfPCell cell = new PdfPCell(im, true);
	cell.setCellEvent(event);
	table.addCell(cell);
	table.addCell("text 3");
	im.setRotationDegrees(0);
	table.addCell(im);
	table.setTotalWidth(300);
	PdfContentByte cb = writer.getDirectContent();
	table.writeSelectedRows(0, -1, 50, 600, cb);
	table.setHeaderRows(3);
	document.add(table);

	// step5
	document.close();
}
 
Example 4
Source File: Conversion.java    From docx4j-export-FO with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.lowagie.text.pdf.PdfPageEventHelper#onEndPage(com.lowagie.text.pdf.PdfWriter, com.lowagie.text.Document)
 */
public void onEndPage(PdfWriter writer, Document document) {
    try {
        Rectangle page = document.getPageSize();

        if (headerFooterPolicy.getHeader(writer.getPageNumber())!=null) {
         Hdr hdr = headerFooterPolicy.getHeader(writer.getPageNumber()).getJaxbElement();
         PdfPTable head = new PdfPTable(1); // num cols	            
         // TODO - no cell borders
         traverseBlockLevelContent( hdr.getEGBlockLevelElts(), head);
         head.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
         head.writeSelectedRows(0, -1, document.leftMargin(), page.getHeight() - document.topMargin() + head.getTotalHeight(),
             writer.getDirectContent());
        }
        
        if (headerFooterPolicy.getFooter(writer.getPageNumber())!=null) {
         Ftr ftr = headerFooterPolicy.getFooter(writer.getPageNumber()).getJaxbElement();	            
         PdfPTable foot = new PdfPTable(1);
         traverseBlockLevelContent( ftr.getEGBlockLevelElts(), foot);
         foot.setTotalWidth(page.getWidth() - document.leftMargin() - document.rightMargin());
         foot.writeSelectedRows(0, -1, document.leftMargin(), document.bottomMargin(),
             writer.getDirectContent());
        }
    }
    catch (Exception e) {
        throw new ExceptionConverter(e);
    }
}
 
Example 5
Source File: StudentCardTest.java    From itext2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Generates a StudentCard
 */
@Test
public void main() throws Exception {

	// step 1: creation of a document-object
	Rectangle rect = new Rectangle(243, 153);
	rect.setBackgroundColor(new Color(0xFF, 0xFF, 0xCC));
	Document document = new Document(rect, 10, 10, 10, 10);

	// step 2:
	PdfWriter writer = PdfWriter.getInstance(document, PdfTestBase.getOutputStream("studentcard.pdf"));

	// step 3: we open the document
	document.open();

	// step 4:
	Font font = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.BOLD, Color.BLUE);
	Paragraph p = new Paragraph("Ghent University", font);
	p.setAlignment(Element.ALIGN_CENTER);
	document.add(p);
	PdfContentByte cb = writer.getDirectContent();
	Font f = FontFactory.getFont(FontFactory.HELVETICA, 8);
	PdfPTable outertable = new PdfPTable(3);
	outertable.setTotalWidth(200);
	outertable.getDefaultCell().setBorder(Rectangle.NO_BORDER);
	float[] outer = { 60, 25, 15 };
	outertable.setWidths(outer);
	PdfPTable innertable = new PdfPTable(2);
	float[] inner = { 35, 65 };
	innertable.setWidths(inner);
	innertable.addCell(new Paragraph("name:", f));
	innertable.addCell(new Paragraph("Bruno Lowagie", f));
	innertable.addCell(new Paragraph("date of birth:", f));
	innertable.addCell(new Paragraph("June 10th, 1970", f));
	innertable.addCell(new Paragraph("Study Program:", f));
	innertable.addCell(new Paragraph("master in civil engineering", f));
	innertable.addCell(new Paragraph("option:", f));
	innertable.addCell(new Paragraph("architecture", f));
	outertable.addCell(innertable);
	outertable.getDefaultCell().setBackgroundColor(new Color(0xFF, 0xDE, 0xAD));
	outertable.addCell(Image.getInstance(PdfTestBase.RESOURCES_DIR + "bruno.jpg"));
	BarcodeEAN codeEAN = new BarcodeEAN();
	codeEAN.setCodeType(Barcode.EAN13);
	codeEAN.setCode("8010012529736");
	Image imageEAN = codeEAN.createImageWithBarcode(cb, null, null);
	imageEAN.setRotationDegrees(90);
	outertable.getDefaultCell().setBackgroundColor(Color.WHITE);
	outertable.addCell(imageEAN);
	outertable.writeSelectedRows(0, -1, 20, 100, writer.getDirectContent());

	// step 5: we close the document
	document.close();
}