Reputation: 3823
I'm trying to place a line separator in the footer of the generated PDF document using iTextSharp like following:
public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
int pageN = writer.PageNumber;
String text = "Page " + pageN + " / ";
float len = bf.GetWidthPoint(text, 8);
Rectangle pageSize = document.PageSize;
cb.SetRGBColorFill(0, 0, 0);
cb.BeginText();
cb.SetFontAndSize(bf, 8);
cb.SetTextMatrix(pageSize.GetRight(90), pageSize.GetBottom(90));
cb.ShowText(text);
cb.EndText();
cb.AddTemplate(template, pageSize.GetRight(90) + len, pageSize.GetBottom(90));
// line separator is here
cb.SetLineWidth(2.0f); // Make a bit thicker than 1.0 default
cb.MoveTo(20, document.Top - 40f);
cb.LineTo(400, document.Top - 40f);
cb.Stroke();
}
I'm trying to place the line exactly below the page number like following:
Document doc = new Document(iTextSharp.text.PageSize.A4,50,50,120,40);
Where values are:
50 - margin left
50 - margin right
120 - margin top
40 - margin bottom
The MoveTo and LineTo method accept parameters as following:
MoveTo(x axis, y axis);
LineTo(x axis, y axis);
Can someone help me out to calculate this? :)
Edit: Just did it
cb.MoveTo(50f, 80f);
cb.LineTo(document.PageSize.Width-document.RightMargin, 80f);
Just in case someone else in the future needs it;
Upvotes: 0
Views: 84
Reputation: 3823
Okay so this trick did it (for those who might need it in future):
cb.MoveTo(50f, 80f);
cb.LineTo(document.PageSize.Width-document.RightMargin, 80f);
These are the values that I've calculated based on my PDF document's margin that I've shown in my question and they are:
50
50
120
40
You can tell how it's done just by looking at the numbers passed into the LineTo and MoveTo methods;
Cheers
Upvotes: 1