Articles in this section
Category / Section

How to set page breaks while exporting WinForms GridControl to PDF?

1 min read

PDF Exporting


Page breaks can be set while exporting GridControl as PDF by passing row count for each PDF page in the GridPDFConverter.ExportToPdf method. The PDF pages are merged as a single PDF file and finally saved.

private void Exportbutton_Click(object sender, EventArgs e)
{
    var converter = new GridPDFConverter();
    var lowest = 0;
 
    //Adding page breaks to a list.
    var rows = new List<int> {30, 63, 90, 130, 150};
 
    var pdfDocument = new PdfDocument();
    pdfDocument.Save("Sample.pdf");
    foreach (var rownumber in rows)
    {
        var pdf = new PdfDocument();
        var maximumRow = rownumber;
        converter.ExportToPdf(pdf, gridControl1, GridRangeInfo.Rows(lowest, maximumRow));
        var stream = new MemoryStream();
        pdf.Save(stream);
        var loadedDocument = new PdfLoadedDocument("Sample.pdf");
        loadedDocument =
            PdfDocumentBase.Merge(loadedDocument, new PdfLoadedDocument(stream)) as PdfLoadedDocument;
        loadedDocument.Save("Sample.pdf");
        loadedDocument.Close(true);
        stream.Dispose();
        lowest = maximumRow + 1;
    }
    var loadedDocument1 = new PdfLoadedDocument("Sample.pdf");
    loadedDocument1.Pages.RemoveAt(0);
    loadedDocument1.Save("Sample.pdf");
    Process.Start("Sample.pdf");
}

Sample: Export GridControl to PDF

Reference Link: Exporting

 

Conclusion

I hope you enjoyed learning about how to set page breaks while exporting WinForms GridControl to PDF.


You can refer to our WinForms GridControl feature tour page to know about its other groundbreaking feature representations and WinForms GridControl documentation, and how to quickly get started for configuration specifications.


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


If you have any queries or require clarifications, please let us know in the comments section 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)
Please  to leave a comment
Access denied
Access denied