I´m trying to get my pdf document to start at (0,0) however it seems that the document object has a default top margin which I cannot set to 0. Is there a way to do this?
My code looks like the following
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 get to set the top margin to 0. It just doesnt care about my setting to (0,0,0,0) and leaves a top margin (around 50f).
You'll need to set your margins in your Document constructor, like this:
Document pdf = new Document(new Rectangle(288f, 144f), 0, 0, 0, 0);
You won't need to use the Document.SetMargins()
method. I believe you'd use SetMargins()
after you create a new page by calling Document.NewPage()
.
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 size paper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With