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.


 c1TrueDBGrid1.PrintInfo.SaveAsC1d("1.c1d");  
 c1TrueDBGrid2.PrintInfo.SaveAsC1d("2.c1d");  

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:  
     doc1.Body.Children.RemoveAt(0);  
     // now add to the combined doc:  
     doc.Body.Children.Add(ro);  
  }  
  // 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];  
     doc2.Body.Children.RemoveAt(0);  
     doc.Body.Children.Add(ro);  
   }  
     doc.Export("CombinedPDF.pdf", true);  
     System.Diagnostics.Process.Start("CombinedPDF.pdf");  

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