Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set page margins with iTextSharp

I have a template PDF file that has a a PDF form field embedded in. I am using PdfStamper to fill out these fields. In addition, I would like to be able to change the margins for generated PDF. is there any way I can modify the page margins on the stamped PDF?

like image 398
Tyler Schroeder Avatar asked Feb 11 '12 01:02

Tyler Schroeder


2 Answers

You can do it all in one line.

Document doc = new Document(PageSize.LETTER, 0f, 0f, 0f, 0f );
like image 178
Baxter Avatar answered Nov 14 '22 19:11

Baxter


Only way I know of is like this.

iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(pageWidth, pageHeight); 
Document doc = new Document(rec); 
doc.SetMargins(0f, 0f, 0f, 0f);

However, this will limit margins too

like image 41
Lukas Avatar answered Nov 14 '22 19:11

Lukas