Hi all-
Paulo asked to see some code regarding the top-margin issue and I have
included it below. This "nothing" program will create a four page PDF
that has a table in the header with 3 cells. In the onEndPage() method
I set the top margin at document.top() + 30, and while the the table
appears properly on every page, the text on the first page is one line
higher up the page than on subsequent pages. I'm really not sure why.
Anyway, I really appreciate any assistance in figuring out what I'm
doing wrong, or missing, or whatever it might be.
Tacho
Code follows:
package com.nobody;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.ExceptionConverter;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfPageEventHelper;
import com.lowagie.text.pdf.PdfWriter;
public class Nothing
{
public class EndPage extends PdfPageEventHelper
{
public void onEndPage(PdfWriter writer, Document document)
{
String cell3 = "Page " + writer.getPageNumber();
Rectangle page = document.getPageSize();
PdfPTable header;
header = new PdfPTable(3);
header.setTotalWidth(page.getWidth() -
document.leftMargin() -
document.rightMargin());
header.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER);
header.addCell(new Phrase(new Chunk("Cell 1")));
header.addCell(new Phrase(new Chunk("Cell 2")));
header.addCell(new Phrase(new Chunk(cell3)));
header.writeSelectedRows( 0,
-1,
document.leftMargin(),
document.top() + 30,
writer.getDirectContent());
}
}
public Nothing()
{
try
{
Document document = new Document(PageSize.LETTER, 15,
15, 50, 50);
PdfWriter docWriter = PdfWriter.getInstance(document,
new FileOutputStream("./Top_Margin_Test.pdf"));
docWriter.setPageEvent(new EndPage());
document.open();
for (int j = 0; j != 300; ++j)
{
document.add(new Phrase("Aloha from beautiful
Waikiki Beach, in
Honolulu Hawaii! Wish you were here!"));
}
document.close();
docWriter.close();
}
catch (DocumentException de)
{
System.err.println(de.getMessage());
}
catch (IOException ioe)
{
System.err.println(ioe.getMessage());
}
}
public static void main(String[] args)
{
new Nothing();
}
}
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.1t3xt.com/docs/book.php