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 Jun 10, 2015 3:04 pm

I use a grid with 2 header rows and I noticed that when there is just a little space left on the page and pagination takes place header is missing.

jbojcic
 
Posts: 23
Joined: Mon Apr 13, 2015 3:03 pm

Thu Jun 11, 2015 6:08 am

Hello,

Thanks for your inquiry.
Please first try to create template, then draw your content in it.
Here is the sample code for your reference.
Code: Select all
PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins margin = new PdfMargins();
            margin.Top = unitCvtr.ConvertUnits(2f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left = unitCvtr.ConvertUnits(0.5f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right = margin.Left;

            SetDocumentTemplate(doc, PdfPageSize.A4, margin);

            // Create one page
            PdfPageBase page = doc.Pages.Add();

            DrawPage(page);

            doc.SaveToFile("output.pdf");
            System.Diagnostics.Process.Start("output.pdf");
        }
        static void SetDocumentTemplate(PdfDocument doc, SizeF pageSize, PdfMargins margin)
        {
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);
            PdfPageTemplateElement bottomSpace = new PdfPageTemplateElement(pageSize.Width, margin.Bottom);
            bottomSpace.Foreground = true;
            doc.Template.Bottom = bottomSpace;
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 9f, FontStyle.Italic));
            float y = 0;
            PdfPageNumberField pageNumber = new PdfPageNumberField();
            PdfPageCountField pageCount = new PdfPageCountField();
            PdfCompositeField pageNumberLabel = new PdfCompositeField();
            pageNumberLabel.AutomaticFields = new PdfAutomaticField[] { pageNumber, pageCount };
            pageNumberLabel.Brush = PdfBrushes.Black;
            pageNumberLabel.Font = font;
            pageNumberLabel.StringFormat = format;
            pageNumberLabel.Text = "page {0} of {1}";
            pageNumberLabel.Draw(bottomSpace.Graphics, pageSize.Width - 150, y);
        }
        static void DrawPage(PdfPageBase page)
        {

            PdfGrid grid = new PdfGrid();
            //Add column
            grid.Columns.Add(4);
            for (int i = 0; i < 30; i++)
            {
                PdfGridRow row = grid.Rows.Add();
                row.Height = 40f;
            }
            grid.Draw(page, new PointF(10, 10));
           
        }


Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Fri Jun 12, 2015 9:12 am

Hello,

Have you tried the code?
Has your issue been resolved?
Thanks for your feedback.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Wed Jun 17, 2015 4:40 pm

I already have a template created and still this is happening. I made a workarround for now by checking a header height before drawing a table:

Code: Select all

if (y + grid.Headers[0].Height + grid.Headers[1].Height > page.Canvas.ClientSize.Height)
{
       page = doc.Pages.Add();
       y = 0;
}


jbojcic
 
Posts: 23
Joined: Mon Apr 13, 2015 3:03 pm

Thu Jun 18, 2015 6:12 am

Hello,

Thanks for your response.
I am glad to hear that you solved your issue.
Please feel free to contact us, if you have any questions or needs. We are here for help.

Best Regards,
Sweety

E-iceblue support team
User avatar

sweety1
 
Posts: 539
Joined: Wed Mar 11, 2015 1:14 am

Return to Spire.PDF