2008年12月3日 星期三

IText Document Margin Setting Trick

Setting the margin of the pdf is a common task for pdf generation.
I encounter a problem when setting the margin that is the setting always effect on the next page, this means the margin setting in never correct on first page.
After few minutes search on Google, I found if you want to have a correct margin on first page, you should let your margin setting done before you open the document.
Here is the code:

Document document = new Document(PageSize.A4.rotate());
try {
PdfWriter writer =
PdfWriter.getInstance(document, new
FileOutputStream("jTable.pdf"));
document.setMargins(200,200,200,200);
document.open();
// add your pdf content here....
}

沒有留言: