Hi Paulo,
I am trying to create a PdfPTable with some text
above the table. Unfortunately, when I run the code,
it didn't shows what I expected. The table below the
text "Header" should fit in a page with the necessary
number of rows per page. Unfortunately, the text
"Header" solely written in the first page. I am using
PdfPTable and I "believe", I followed the suggestions
posted on the mailing list by using the
PdfWriter.fitsPage(). Please let me know if I did
something stupid in my code?
Regards,
ogagz
*******************************
package testitext.table;
import java.io.FileOutputStream;
import java.awt.Color;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.PageSize;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Element;
import com.lowagie.text.Phrase;
import com.lowagie.text.Cell;
public class MultipleTable {
public static void main(String[] args) {
new MultipleTable();
}
public MultipleTable() {
Document document = new
Document(PageSize.A4.rotate(), 15, 15, 40, 20);
try {
PdfWriter pdfWriter=
PdfWriter.getInstance(document, new
FileOutputStream("TableSample.pdf"));
document.open();
PdfPTable[] borderTable= new PdfPTable[2];
PdfPTable mainTable = new PdfPTable(1);
borderTable[0]= new PdfPTable(1);
borderTable[1]= new PdfPTable(1);
borderTable[0].setWidthPercentage(100);
Font headerFont=
FontFactory.getFont(FontFactory.HELVETICA, 8,
Font.BOLD);
Phrase phrase= new Phrase("", headerFont);
document.add(new Paragraph("Header"));
for(int i= 0; i < 75; i++) {
if (!pdfWriter.fitsPage(mainTable)) {
document.newPage();
}
mainTable.addCell(phrase.getInstance(0, "Sample",
headerFont));
}
if (!pdfWriter.fitsPage(borderTable[0])) {
document.newPage();
}
borderTable[0].addCell(mainTable);
if (!pdfWriter.fitsPage(borderTable[1])) {
document.newPage();
}
borderTable[1].setSpacingBefore(10f);
borderTable[1].addCell(mainTable);
document.add(borderTable[0]);
document.add(borderTable[1]);
document.close();
System.out.println("Done!");
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO September
19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions