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.
Unfortunately, activation email could not send to your email. Please try again.

Get PdfGrid height before drawing

Thread ID:

Created:

Updated:

Platform:

Replies:

104250 Jul 3,2012 06:55 PM Jul 9,2012 02:50 AM ASP.NET Web Forms (Classic) 4
loading
Tags: PDF
Administrator [Syncfusion]
Asked On July 3, 2012 06:55 PM

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.


Administrator [Syncfusion]
Replied On July 3, 2012 07:49 PM

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;
        }

Geetha M [Syncfusion]
Replied On July 5, 2012 03:29 AM

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

Administrator [Syncfusion]
Replied On July 6, 2012 12:28 PM

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

Geetha M [Syncfusion]
Replied On July 9, 2012 02:50 AM

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

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;