The easiest way of saving FlexGrid as a PDF is to use the System.PrintDocument class. You can set its PrinterName property to "Microsoft Print to PDF" and invoke Print method of the class.
However, this approach has some limitations and it does not let you set advanced options such as setting borders, printing by specific page or column breaks etc. To implement these kind of advanced export options, you can use the C1PrintDocument class of the C1PrintDocument library shipped with ComponentOne WinForms Edition as shown in the section below.
To export a grid to PDF with advanced options, you need to create images of grid by defining the rows and columns per page and hence, finding the row and column range to be drawn on each page. Then, add these images to generate a PDF using the C1PrintDocument class. Below are the detailed steps and sample code to implement the advanced export to PDF.
First, you need to set the UserData property according to the defined rows per page and columns per page. This helps in finding out the row and column range to be drawn on each page of the PDF document. So, this step acts as a ground to create images of the grid in the step below.
Now, create a custom class (in this case, FlexPDFCreator) to create images of the grid using CreateImage method of the C1FlexGrid class. The images are created based on the UserData property set in the step above.
In this step, create a document using C1PrintDocument class of the C1PrintDocument library shipped with ComponentOne WinForms Edition. Use the RenderImage class to add created images to this document and finally, save the PDF document using Export method.