Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Wed Dec 02, 2015 12:50 am

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!

Rogerlebrun
 
Posts: 1
Joined: Wed Dec 02, 2015 12:14 am

Wed Dec 02, 2015 3:49 am

Hi,

Thanks for your inquiry.
Pdf has two structures, one contains sections which contain pages, the other just contains pages. No matter which kind of structure, both can use pdfDocument.Page[index] to select specific page.
Code: Select all
 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);
        }

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3011
Joined: Wed Jun 27, 2012 8:50 am

Fri Dec 04, 2015 8:17 am

Hi,

Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 3011
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.PDF