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

DataTable passing through a SyncFusion Chart in PDF page

Hi guys

I've attached a PDF file generated by the code below:
----------------------------------------------------------------
string fileName = @"C:\Users\xportal42\Desktop\chartexport";
string exportFileName = fileName + ".pdf";
string file = fileName + ".jpg";
this.ChartWebControl1.SaveImage(file);
Font f = new Font("Calibri", 12f, FontStyle.Bold);
PdfFont pdfFont = new PdfTrueTypeFont(f);

//Create a PDF document
PdfDocument pdfDoc = new PdfDocument();

//Add a page to the empty PDF document
pdfDoc.Pages.Add();

//Draw chart image and add some text and datatable in the first page
pdfDoc.Pages[0].Graphics.DrawString("General Information", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), 25, 5);
pdfDoc.Pages[0].Graphics.DrawString("Education Grade", pdfFont, new PdfSolidBrush(new PdfColor(213, 123, 19)), 200, 5);

// Creating table
PdfLightTable table = new PdfLightTable();
PdfPage page = pdfDoc.Pages[0];
table.DataSourceType = PdfLightTableDataSourceType.External;
// Initializing datasource
table.DataSource = Session["DataToGraphicPDF"] as DataTable;
//table.DataSource = dataTable;
//Set layout properties
PdfLayoutFormat format = new PdfLayoutFormat();
format.Break = PdfLayoutBreakType.FitElement;
format.Layout = PdfLayoutType.Paginate; /////
// Drawing Table
table.Draw(page, new PointF(10,100), format);

pdfDoc.Pages[0].Graphics.DrawImage(Syncfusion.Pdf.Graphics.PdfImage.FromFile(file), new Point(200, 200), new Size(200, 200));

//Save the PDF Document to disk.
pdfDoc.Save(exportFileName);

//Launches the file.
System.Diagnostics.Process.Start(exportFileName);
----------------------------------------------------------------

As you can see PDF file, the dataTable pass through a SyncFusion Chart. How can I solve this? Because the datatable has a variable size (could have over 1000 rows!!!) and all I need is while the dataset grows, the syncfusion stays under the datatable.

Best Regards.



chartexport_ac975710.rar

3 Replies

GM Geetha M Syncfusion Team March 2, 2011 04:07 AM UTC

Hi Victor,

Thank you for the details.

Drawing table returns PdfLightTableLayoutResult with the bounds of the table drawn. You can calculate the new point for the image from that result. Please refer to the code snippet below.

PdfLightTableLayoutResult result = table.Draw(page, new PointF(10, 100), format);
PointF pt = new PointF(result.Bounds.X, result.Bounds.Bottom + 10);
result.Page.Graphics.DrawImage(PdfImage.FromFile(file), pt, new Size(200, 200));

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

Regards,
Geetha



VE victor elizondo March 2, 2011 06:55 PM UTC

Hello

Thanks again. Everything it's ok. The only difference in the code that you provide me is this one:

PdfLightTableLayoutResult result = table.Draw(page, new PointF(10, 100), format) as PdfLightTableLayoutResult;

I have a doubt about something but I guess I must post it in another theme.

BestRegards



Sample_aa48acde.rar


GM Geetha M Syncfusion Team March 3, 2011 03:34 AM UTC

Hi Victor,

Thank you for the update.

Glad to hear that the code snippet worked for you.

Please let us know if you have any other questions.

Regards,
Geetha


Loader.
Live Chat Icon For mobile
Up arrow icon