Articles in this section

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

Multiple Xamarin DataGrid are exported to a single PDF document one at a time using the DataGridPdfExportingController.ExportToPdf method. Merge the exported PDF into a single PDF document using the PdfDocumentBase.Merge in Xamarin.Forms.

C#

Each SfDataGrid is exported into a MemoryStream using the extension method ExportToPdf with the DataGridPdfExportOption, which allows customizing the data exported to the PDF.

   DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
   MemoryStream stream = new MemoryStream();
   var exportToPdf = pdfExport.ExportToPdf(this.sfDataGrid1, new DataGridPdfExportOption()
   {
     FitAllColumnsInOnePage = true,
   });
   exportToPdf.Save(stream);
   exportToPdf.Close(true);
   DataGridPdfExportingController pdfExport1 = new DataGridPdfExportingController();
   MemoryStream stream1 = new MemoryStream();
   var exportToPdf1 = pdfExport1.ExportToPdf(this.sfDataGrid2, new DataGridPdfExportOption()
   {
     FitAllColumnsInOnePage = true,
   });
   exportToPdf1.Save(stream1);
   exportToPdf1.Close(true);
…

C#

Merging the exported stream into Pdf document using PdfDocumentBase.Merge method and save the converted document.

   PdfDocument document = new PdfDocument();
   MemoryStream laststream = new MemoryStream();
   Stream[] source = { stream, stream1 };
   PdfDocumentBase.Merge(document, source);
   document.Save(laststream);
 
   if (Device.RuntimePlatform == Device.UWP)
      Xamarin.Forms.DependencyService.Get<ISaveWindows>().Save("DataGrid.pdf", "application/pdf", laststream);
   else
      Xamarin.Forms.DependencyService.Get<ISave>().Save("DataGrid.pdf", "application/pdf", laststream);

View sample on GitHub

How to export multiple DataGrid to one PDF document in Xamarin.Forms (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 the documentation, where you can find more about SfDataGrid with code examples.

Conclusion

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

You can refer to our  Xamarin. Forms DataGrid’s feature tour page to know about its other groundbreaking feature representations.

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

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-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