How to remove default upper border in pdf using itextsharp?

I am trying to run my pdf document (0,0), however it seems that the document object has a top edge by default, which I cannot set to 0. Is there a way to do this?

My code is as follows

using (MemoryStream memoria = new MemoryStream()) { Document pdf = new Document(new Rectangle(288, 144)); try { PdfWriter writer = PdfWriter.GetInstance(pdf, memoria); pdf.Open(); pdf.SetMargins(0, 0, 0, 0); PdfPTable tPrincipal = new PdfPTable(2); tPrincipal .WidthPercentage = 100; tPrincipal .DefaultCell.Border = 0; tPrincipal .TotalWidth = 288f; tPrincipal .LockedWidth = true; 

....

I just can't set the top margin to 0. It just doesn't care about my setup (0,0,0,0) and leaves the top edge (about 50 feet).

+7
margin itextsharp
source share
2 answers

You will need to set the fields in the document constructor, for example:

 Document pdf = new Document(new Rectangle(288f, 144f), 0, 0, 0, 0); 

You do not need to use the Document.SetMargins() method. I suppose you would use SetMargins() after creating a new page by calling Document.NewPage() .

+14
source share

Option 1:

 Document doc = new Document(); doc.setMargins(0 , 0 , 0 , 0); 

Option 2:

 Document pdf = new Document(new Rectangle(595 , 842 ), 0, 0, 0, 0); 

Where 595x842 is A4 paper.

+1
source share

All Articles