15

It looks like I can't set left margin to be less then 42pt width. I am setting it to 0f but it always ends as 42pt. If I set margin to any number greater then 0 it just adds it to initial margin of 42pt. I am setting margin of document object:

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

Page width and height are 6x9 in.

And I end with:

42pt margin|CONTENT CONTENT

I would appreciate any help. Thanks.

Velja Radenkovic
  • 716
  • 1
  • 6
  • 27
  • How are you adding your content to the Document? That can have an impact on where it is placed by default. – Stewbob Dec 24 '09 at 21:51

3 Answers3

15

I am using PdfPTable and the problem was default PdfPTable horizontal alignment which is CENTER. As soon as I set alignmentof table to left problem went away.

PdfPTable bTable = new PdfPTable(2);
bTable.HorizontalAlignment = Element.ALIGN_LEFT;

Thanks, Velja

Velja Radenkovic
  • 716
  • 1
  • 6
  • 27
10

Well, I think that the problem is different. By default, PdfPTable.LockedWidth property is set to false, and PdfPTable.WidthPercentage is equal to 80f. As long as default table alignment is Center you get the impression that your margins are not honoured... but they are! You sipmly need to set PdfPTable.WidthPercentage = 100f.

stakx - no longer contributing
  • 83,039
  • 20
  • 168
  • 268
Evgeny Koblov
  • 101
  • 1
  • 2
2

Your problem may have to do with how you are adding the content to your document. If you are using a Table (instead of a PdfPTable), even if you have a left margin of 0, the table will still be placed indented from the left margin by default.

The default spacing works out to be about 10% of the width of the printable page area. So the left edge of the Table would be placed at ( 0.10 * (pageWidth - leftMargin - rightMargin)).

10% of 6 inches (at 72 pts per inch) is equal to 43.2 pts, pretty close to the 42 pts you are getting.

Stewbob
  • 16,759
  • 9
  • 63
  • 107