Articles in this section

How to export multiple SfDataGrids sequentially to one PDF document in Xamarin.Forms DataGrid (SfDataGrid) ?

The multiple Xamarin DataGrid are exported to a single PDF document one at a time using the DataGridPdfExportingController.ExportToPdfGrid method. Draw the exported PDF sequentially into a single PDF document using the PdfGrid.Draw in the Xamarin.Forms.

C#

Create a PDF document using the PdfDocument and export the SfDataGrid into a PdfGrid using the extension method ExportToPdfGrid with the DataGridPdfExportOption, which allows customization of the data exported to the PDF.

var pdfDoc = new PdfDocument();
PdfPage page = pdfDoc.Pages.Add();
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
MemoryStream stream = new MemoryStream();
var exportToPdfGrid = pdfExport.ExportToPdfGrid(this.sfDataGrid1, this.sfDataGrid1.View, new DataGridPdfExportOption()
{
   FitAllColumnsInOnePage = true,
}, pdfDoc);
 

C#

Sequentially draw the exported PdfGrid in the PdfPage using the PdfGrid.Draw method and save the created PDF document.

PdfGridLayoutFormat layoutFormat = new PdfGridLayoutFormat();
layoutFormat.Layout = PdfLayoutType.Paginate;
PdfLayoutResult result = exportToPdfGrid.Draw(page, new PointF(10, 10), layoutFormat);
var exportToPdfGrid1 = pdfExport.ExportToPdfGrid(this.sfDataGrid2, this.sfDataGrid2.View, new DataGridPdfExportOption()
{
  FitAllColumnsInOnePage = true,
}, pdfDoc);
exportToPdfGrid1.Draw(result.Page, new PointF(10, result.Bounds.Height + 20));
pdfDoc.Save(stream);
pdfDoc.Close(true);
if (Device.RuntimePlatform == Device.UWP)
   Xamarin.Forms.DependencyService.Get<ISaveWindows>().Save("DataGrid.pdf", "application/pdf", stream);
else
   Xamarin.Forms.DependencyService.Get<ISave>().Save("DataGrid.pdf", "application/pdf", stream);

View sample on GitHub

How to export mutiple SfDataGrids sequentially to one PDF document in Xamarin.Forms DataGrid (SfDataGrid)

 

Note:

Refer to the following documentation link to understand how to export a SfDataGrid to Excel and PDF

How to export a SfDataGrid to excel or PDF using ToolBarItems of a Page?

Take a moment to pursue this documentation, where you can find more about SfDataGrid with code examples.

Conclusion

I hope you enjoyed learning about how to export multiple SfDataGrids sequentially to one PDF document in Xamarin.Forms DataGrid (SfDataGrid).

You can refer to our Xamarin DataGrid’s feature tour page to know about its other groundbreaking feature representations. You can also explore our Xamarin DataGrid Documentation to understand how to present and manipulate data.

For current customers, you can check out our Xamarin components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our Xamarin DataGrid and other Xamarin components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forumsDirect-Trac or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied