Hello,
is there a way to have a header on the first page, but not on the second one, but then a different header on the third page, for example?
Also, what is the pdf structure? Is it a pdf contains sections which contain pages?
Thank you!
PdfDocument doc = new PdfDocument();
doc.LoadFromFile("..\\..\\test.pdf");
AddHeader1(doc.Pages[0]);
AddHeader2(doc.Pages[2]);
string output = "result.pdf";
doc.SaveToFile(output);
System.Diagnostics.Process.Start(output);
public void AddHeader1(PdfPageBase page)
{
PdfSolidBrush brush = new PdfSolidBrush(System.Drawing.Color.Black);
PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Regular), true);
PdfMargins margins = page.Document.PageSettings.Margins;
float space = font.Height;
float x = margins.Left;
float y = margins.Top-space;
page.Canvas.DrawString("This is the first header", font, brush, new PointF(x,y), leftAlignment);
}
public void AddHeader2(PdfPageBase page)
{
PdfSolidBrush brush = new PdfSolidBrush(System.Drawing.Color.Black);
PdfStringFormat leftAlignment = new PdfStringFormat(PdfTextAlignment.Left, PdfVerticalAlignment.Top);
PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 8f, FontStyle.Regular), true);
PdfMargins margins = page.Document.PageSettings.Margins;
float space = font.Height;
float x = margins.Left;
float y = margins.Top - space;
page.Canvas.DrawString("This is the second header", font, brush, new PointF(x, y), leftAlignment);
}