We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Get PdfGrid height before drawing

I need to check if my dynamic sized grid is going to fit on the current page.
I'm using the code like:
                float y = pagebounds.Bottom + 10;

                if (y > page.GetClientSize().Height - gridHeight)
                {
                    page = doc.Pages.Add();
                    y = 0;
                }
 myGrid.Draw(page, new PointF(0, y));

instead of 10, I need to know the value for myGrid height.  Anyway to get this without looping through the rows? I guess that's what I'll do.


4 Replies

AD Administrator Syncfusion Team July 3, 2012 11:49 PM UTC

I made a method below, but if I pass PdfPage page, it doesn't change the current page unless I use a global,  static PdfPage page; instead of passing the page.  Maybe I'm a little braindead now, but how can I do it so I can pass the page and have the page change without having to pass it back.  Maybe I should just pass the resultg back because that has the bounds and the page.



        public static float drawGridAuto(PdfDocument doc,PdfPage page, float currentY, PdfGrid grid )
        {
            float botMarg = 10;
            PdfGridLayoutFormat gformat = new PdfGridLayoutFormat();
            gformat.Layout = PdfLayoutType.Paginate;
            gformat.Break = PdfLayoutBreakType.FitElement;

            float totalHeight = 0;
            foreach (var a in grid.Rows)
            {
                totalHeight = totalHeight + a.Height;
            }
            if (currentY > page.GetClientSize().Height - totalHeight)
            {
                page = doc.Pages.Add();
                currentY = 0;
            }
            PdfGridLayoutResult resultg = grid.Draw(page, new PointF(0, currentY), gformat);
            RectangleF bounds = resultg.Bounds;
            currentY = bounds.Bottom + botMarg;

            return currentY;
        }


GM Geetha M Syncfusion Team July 5, 2012 07:29 AM UTC

Hi Dan,

Thank you for the details.

Could you please let us know if you want to achieve automatic pagination when drawing PdfGrid? It is already supported and you may supply PdfGridLayoutFormat with pagination type and get PdfGridLayoutResult with last bounds and page after drawing. Please check the following documentation for more details:

<a rel='nofollow' href="http://help.syncfusion.com/UG/Reporting/PDF/Windows%20Forms/default.htm#!documents/4123222layout.htm">Layout</a>

If you want to do manipulations based on PdfGrid height, then you can add the Grid in a temporary PdfPage, know the height and then remove the page.

int pageCount = doc.Sections[0].Pages.Count;

// Add a temp Page.
PdfPage tempPage = doc.Pages.Add();

DuplicateGrid(tempPage);

// Remove temp page.
for (int i = doc.Sections[0].Pages.Count; i > pageCount; i--)
    doc.Sections[0].Pages.Remove(doc.Sections[0].Pages[i - 1]);

Please try this and let me know if you have any questions.

Regards,
Geetha


AD Administrator Syncfusion Team July 6, 2012 04:28 PM UTC

thanks, my width in my grid was to too large, so the paginate wasn't working.  Everything was ok when I fixed that.


GM Geetha M Syncfusion Team July 9, 2012 06:50 AM UTC

Hi Dan,

Thank you for the update. Glad to hear that the issue is resolved.

Please let us know if you have any questions.

Regards
Geetha

Loader.
Live Chat Icon For mobile
Up arrow icon