|
1 | | -# How-to-set-page-breaks-while-exporting-GridControl-to-pdf |
2 | | -This example demonstrates how to set page breaks while exporting [GridControl](https://help.syncfusion.com/windowsforms/grid/getting-started?utm_medium=listing&utm_source=github-examples) to PDF. |
3 | | -See [How to set page breaks while exporting GridControl to pdf?](https://www.syncfusion.com/kb/9635?utm_medium=listing&utm_source=github-examples) for more details. |
| 1 | +# How to Set Page Breaks While Exporting WinForms GridControl to PDF? |
| 2 | + |
| 3 | +This example demonstrates how to set page breaks while exporting [WinForms GridControl](https://www.syncfusion.com/winforms-ui-controls/grid-control) to PDF. |
| 4 | + |
| 5 | +Page breaks can be set while exporting GridControl as PDF by passing row count for each PDF page in the [GridPDFConverter.ExportToPdf](https://help.syncfusion.com/cr/windowsforms/Syncfusion.GridHelperClasses.GridPDFConverter.html#Syncfusion_GridHelperClasses_GridPDFConverter_ExportToPdf_Syncfusion_Pdf_PdfDocument_Syncfusion_Windows_Forms_Grid_GridControlBase_Syncfusion_Windows_Forms_Grid_GridRangeInfo_) method. The PDF pages are merged as a single PDF file and finally saved. |
| 6 | + |
| 7 | +``` csharp |
| 8 | +private void Exportbutton_Click(object sender, EventArgs e) |
| 9 | +{ |
| 10 | + var converter = new GridPDFConverter(); |
| 11 | + var lowest = 0; |
| 12 | + |
| 13 | + //Adding page breaks to a list. |
| 14 | + var rows = new List<int> {30, 63, 90, 130, 150}; |
| 15 | + |
| 16 | + var pdfDocument = new PdfDocument(); |
| 17 | + pdfDocument.Save("Sample.pdf"); |
| 18 | + foreach (var rownumber in rows) |
| 19 | + { |
| 20 | + var pdf = new PdfDocument(); |
| 21 | + var maximumRow = rownumber; |
| 22 | + converter.ExportToPdf(pdf, gridControl1, GridRangeInfo.Rows(lowest, maximumRow)); |
| 23 | + var stream = new MemoryStream(); |
| 24 | + pdf.Save(stream); |
| 25 | + var loadedDocument = new PdfLoadedDocument("Sample.pdf"); |
| 26 | + loadedDocument = PdfDocumentBase.Merge(loadedDocument, new PdfLoadedDocument(stream)) as PdfLoadedDocument; |
| 27 | + loadedDocument.Save("Sample.pdf"); |
| 28 | + loadedDocument.Close(true); |
| 29 | + stream.Dispose(); |
| 30 | + lowest = maximumRow + 1; |
| 31 | + } |
| 32 | + var loadedDocument1 = new PdfLoadedDocument("Sample.pdf"); |
| 33 | + loadedDocument1.Pages.RemoveAt(0); |
| 34 | + loadedDocument1.Save("Sample.pdf"); |
| 35 | + Process.Start("Sample.pdf"); |
| 36 | +} |
| 37 | +``` |
| 38 | + |
| 39 | +Take a moment to peruse the [WinForms GridControl - PDF Exporting](https://help.syncfusion.com/windowsforms/grid-control/exporting#pdf-exporting) documentation, where you can find about PDF exporting with code examples. |
0 commit comments