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.

5 Replies

SL Sowmiya Loganathan Syncfusion Team October 4, 2017 12:25 PM UTC

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. 

Regards, 
Sowmiya L 



VC Vladimir Culum October 4, 2017 10:24 PM UTC

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 11:14 AM UTC

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. 

Regards, 
Sowmiya L 



PU pudjo January 9, 2024 01:08 AM UTC

How iif secon grid in other page? Probably first grid need more than one page



JT Jeyalakshmi Thangamarippandian Syncfusion Team January 9, 2024 12:35 PM UTC

Hi pudjo,

We have created a sample for adding multiple pdf grids using PdfGridLayoutResult. Drawing of the second grid onto the same page where the first grid was drawn, positioned below the first grid with an offset determined by the first grid's bounds. However, we have attached the sample for your reference. We kindly request you to try it out and let us know if you require any further assistance.

Please find the code snippet below,

//Create a new PDF document.

 

PdfDocument doc = new PdfDocument();

 

//Add a page.

 

PdfPage page = doc.Pages.Add();

 

//Create a PdfGrid.

 

PdfGrid pdfGrid = new PdfGrid();

 

//Add values to the list.

List<object> data = new List<object>();

Object grid1row1 = new { ID = "E01", Name = "Clay", Salary = "$10,000" };

          

for(int  i = 0; i < 75; i++)

{

   data.Add(grid1row1);

}

          

 

//Add list to IEnumerable.

IEnumerable<object> dataTable = data;

 

//Assign data source.

 

pdfGrid.DataSource = dataTable;

 

PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();

layoutFormat.Layout = PdfLayoutType.Paginate;

 

//Draw grid to the page of PDF document.

 

PdfGridLayoutResult result = pdfGrid.Draw(page, new PointF(0, 0),layoutFormat);

 

//Create a PdfGrid.

 

PdfGrid pdfGrid1 = new PdfGrid();

 

//Add values to the list.

List<object> data1 = new List<object>();

Object grid1Row1 = new { ID = "E01", Name = "Thomas", Salary = "$10,000" };

          

for(int j= 0; j < 10; j++)

{

   data1.Add(grid1Row1);

}

          

//Add list to IEnumerable.

IEnumerable<object> dataTable1 = data1;

//Assign data source.

 

pdfGrid1.DataSource = dataTable1;

 

PdfLayoutResult result1 = pdfGrid1.Draw(result.Page, new PointF(0, result.Bounds.Bottom + 40), layoutFormat);

        

doc.Save("Output.pdf");

doc.Close(true);

System.Diagnostics.Process.Start("Output.pdf");


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/Multiplegrid_Sample-866264740.zip


Regards,

Jeyalakshmi T


Loader.
Live Chat Icon For mobile
Up arrow icon