views:

19

answers:

1

Hi, 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).

A: 

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().

Jay Riggs
Thanks Jay that did work, however I had to include the "f" after all ceros. Document pdf = new Document(new Rectangle(288f, 144f), 0f, 0f, 0f, 0f);
Lilian