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

adding multiple pdf grids

Hello, I am trying to add 2 PdfGrid one after another.

I am adding first one with PdfGridLayoutResult = PdfGrid.Draw(page...)

When I try to add another PdfGrid, it overlaps with first one (if there is multiple pages), because property ...bouds.height is taking height of first grid on last page.

How to add second grid after first one.

Thank You.

3 Replies

SL Sowmiya Loganathan Syncfusion Team October 4, 2017 07:25 AM

Hi Vladimir, 

We can draw PdfGrid one below another. To avoid overlap make sure you have drawn with the resultant page of the first. Please refer the below code snippet for more details. 

            //Create a new PDF document. 
            PdfDocument doc = new PdfDocument(); 
            //Add a page. 
            PdfPage page = doc.Pages.Add(); 
            //Create a PdfGrid. 
            PdfGrid pdfGrid = new PdfGrid(); 
            //Assign data source. 
            pdfGrid.DataSource = dataTable; 
            //Draw grid to the page of PDF document. 
            PdfLayoutResult result=pdfGrid.Draw(page, new PointF(10, 10)); 
            //Create a PdfGrid. 
            PdfGrid pdfGrid1 = new PdfGrid(); 
            //Assign data source. 
            pdfGrid1.DataSource = dataTable1; 
            //Draw grid to the page of PDF document. 
            pdfGrid1.Draw(result.Page, new PointF(10, result.Bounds.Height+20)); 

Please try the code snippet in your end and let us know if it solves your issue. 

Sowmiya L 

VC Vladimir Culum October 4, 2017 05:24 PM

Hello Sowmiya,

This does not resolve my problem. It seems that drawing on the page does not change layout height.

I have:

PdfLayoutResult result = reportTitle.Draw(page, new PointF()); //this is ok. title is on the page

PdfGrid plgrid = new PdfGrid();
DataTable pldt = new DataTable();

PdfGrid plgrid2 = new PdfGrid();
DataTable pldt2 = new DataTable();

...assigning values to the pldt and pldt2

plgrid.DataSource = pldt;

plgrid2.DataSource = pldt2;

PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
layoutFormat.Layout = PdfLayoutType.Paginate;

plgrid.Draw(result.Page, new PointF(0, result.Bounds.Height + 40)); //this is ok. grid is under title +40

plgrid2.Draw(result.Page, new PointF(0, result.Bounds.Height + 30)); //this is NOT ok. it is drawn under title +30

When I run debug I try to trace result.Bounds values and it is not changing and it seems to be a problem:

var rb = result.Bounds.Bottom;
var rh = result.Bounds.Height;

Hope that sample code can help us to resolve the issue.

Thank You for the initial help.

Regards, Vladimir.

SL Sowmiya Loganathan Syncfusion Team October 5, 2017 06:14 AM

Hi Vladimir, 

We have analyzed with the code snippet provided by you, and modified your code snippet accordingly. 
PdfGridLayoutResult result = pdfGrid.Draw(pdfPage, PointF.Empty); 
PdfGrid pdfGrid1 = new PdfGrid(); 
pdfGrid1.DataSource = dataTable1; 
PdfGrid pdfGrid2 = new PdfGrid(); 
pdfGrid2.DataSource = dataTable2; 
PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat(); 
layoutFormat.Layout = PdfLayoutType.Paginate; 
PdfLayoutResult result1=pdfGrid1.Draw(result.Page, new PointF(0, result.Bounds.Height + 40), layoutFormat); 
pdfGrid2.Draw(result1.Page, new PointF(0, result1.Bounds.Height + 30), layoutFormat); 

Please try this in your side and let us know if you need further assistance. 

Sowmiya L 

Live Chat Icon For mobile
Up arrow icon