Export Windows form to PDF

2 posts, 0 answers
  1. David
    David avatar
    3 posts
    Member since:
    Sep 2014

    Posted 16 Dec 2015 Link to this post


         I have a form in a windows application. The form contains grids, table, images, other data and a link called PDF generate. What is the best way to generate a pdf with the same format on the form with all the data using telerik controls?


  2. Dimitar
    Dimitar avatar
    1328 posts

    Posted 21 Dec 2015 Link to this post

    Hi Dav,

    Thank you for writing.

    The easiest way to achieve this is to put the controls which you want to export to a panel. Then take a snapshot of the panel and add it to a pdf file. For example:
    private void radButton1_Click(object sender, EventArgs e)
        Bitmap bmp = new Bitmap(this.radPanel1.Width, this.radPanel1.Height);
        radPanel1.DrawToBitmap(bmp, new Rectangle(Point.Empty, this.radPanel1.Size));
        RadFixedDocument document = new RadFixedDocument();
        RadFixedPage page = document.Pages.AddPage();
        page.Size = new System.Windows.Size(radPanel1.Width, radPanel1.Height);
        using (MemoryStream ms = new MemoryStream())
            bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            Telerik.Windows.Documents.Fixed.Model.Objects.Image image = new Telerik.Windows.Documents.Fixed.Model.Objects.Image();
            image.ImageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(ms);
            image.Width = radPanel1.Width;
            image.Height = radPanel1.Height;
        PdfFormatProvider provider = new PdfFormatProvider();
        using (Stream output = File.OpenWrite("Test.pdf"))
            provider.Export(document, output);

    Another way would be to manually construct the entire pdf document. The following article shows how you can create complex documents: Getting Started with RadPdfProcessing.

    I hope this helps.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top