Exporting data to a PDF file is one of the most commonly preferred features in the .NET world. The essential ComponentOne TrueDbGrid for WinForms control has in-built support for PDF export. ExportToPDF method provides support for exporting data from a C1TrueDbGrid control to a PDF file. However, using ExportToPDF() method we can't export multiple C1TrueDbGrids to a single PDF file.

Hence, in this blog we will discuss an approach to export multiple ComponentOne TrueDbGrids for WinForms to a single PDF file. It's a two step procedure:-

1. Export C1TrueDbGrids to 'c1d' files

After binding multiple C1TrueDbGrid we need to save them to 'c1d' files separately.


2. Use C1PrintDocument to load and save 'c1d' files to PDF

Then use multiple C1PrintDocuments to load 'c1d' files separately and then combine RenderObjects of those multiple C1PrintDocuments in a single C1PrintDocument and export it to a PDF file.

 C1PrintDocument doc1 = new C1PrintDocument();
 doc1.Load("1.c1d", C1DocumentFormatEnum.C1d);

 C1PrintDocument doc2 = new C1PrintDocument();
 doc2.Load("2.c1d", C1DocumentFormatEnum.C1d);

 // the combined document:
 C1PrintDocument doc = new C1PrintDocument();
 // add 1st document:
 while (doc1.Body.Children.Count > 0)
     RenderObject ro = doc1.Body.Children[0];
     // a render object cannot have two parents at once, so removed from original parent first:
     // now add to the combined doc:
  // ensure a page break between the two documents:
  doc.Body.Children.Add(new RenderEmpty(BreakEnum.Page));
  // add 2nd document:
  while (doc2.Body.Children.Count > 0)
     RenderObject ro = doc2.Body.Children[0];
     doc.Export("CombinedPDF.pdf", true);

This concludes our blog. You can download the samples for detailed implementation.