This is a migrated thread and some comments may be shown as answers.

Export Windows form to PDF

1 Answer 605 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 16 Dec 2015, 07:43 PM

Hello

     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?

 

1 Answer, 1 is accepted

Sort by
0
David
Top achievements
Rank 1
answered on 21 Dec 2015, 08:49 AM
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;
       
        document.Pages.First().Content.Add(image);
    }
 
    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.

Regards,
Dimitar
Telerik
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
Tags
PdfProcessing
Asked by
David
Top achievements
Rank 1
Answers by
David
Top achievements
Rank 1
Share this question
or