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

TextBox export to PDF

6 Answers 82 Views
Chart
This is a migrated thread and some comments may be shown as answers.
GOURVEZ JJ
Top achievements
Rank 1
GOURVEZ JJ asked on 30 Jan 2012, 05:03 PM
Hi,

I use an RadChart.
I want to export it, I use this code : http://demos.telerik.com/silverlight/#Chart/PrintAndExportWithRadDocument

All it's OK but, I want export TextBox and Label.
Can you help me ?

Thanks

6 Answers, 1 is accepted

Sort by
0
GOURVEZ JJ
Top achievements
Rank 1
answered on 01 Feb 2012, 11:20 AM
Nobody ???
0
Vladimir Milev
Telerik team
answered on 02 Feb 2012, 12:13 PM
Hi,

To export them to image you can use the export extensions:

private void Export_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.DefaultExt = "png";
sfd.Filter = "PNG File (*.png) | *.png";
if ((bool)sfd.ShowDialog())
{
using (var stream = sfd.OpenFile())
{
Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(control_to_export, stream, new PngBitmapEncoder());
}
}
}


Regards,
Vladimir Milev
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
GOURVEZ JJ
Top achievements
Rank 1
answered on 02 Feb 2012, 05:52 PM
Thanks for your answer.
But I want export to PDF.
Does it possible ?
Thanks
0
GOURVEZ JJ
Top achievements
Rank 1
answered on 07 Feb 2012, 09:55 AM
Hi,

Does it possible to export to PDF ? (Radchart, textbox and  label)

Thanks
0
Iva Toteva
Telerik team
answered on 07 Feb 2012, 10:18 AM
Hi GOURVEZ,

You can use RadDocument and PdfFormatProvider to create a document and export it to PDF. You can find more information on this in our online documentation, in the articles about RadDocument and the FormatProviders.
In a nutshell, what you can do is use the export extension method from Vladimir's post to create an image out of the control you wish to export, insert this image into the document and save the document to PDF. This can be done as follows:

private void Export_Click(object sender, System.Windows.RoutedEventArgs e)
{
    SaveFileDialog sfd = new SaveFileDialog();
    sfd.DefaultExt = "pdf";
    sfd.Filter = "PDF File (*.pdf) | *.pdf";
    if ((bool)sfd.ShowDialog())
    {
        RadDocument document = new RadDocument();
        using (var stream = new MemoryStream())
        {
            Telerik.Windows.Media.Imaging.ExportExtensions.ExportToImage(controlToExport, stream, new PngBitmapEncoder());
            stream.Flush();
            stream.Seek(0, SeekOrigin.Begin);
            document.InsertInline(new ImageInline(stream));
        }
        using (var stream = sfd.OpenFile())
        {
            PdfFormatProvider pdf = DocumentFormatProvidersManager.GetProviderByExtension("pdf") as PdfFormatProvider;
            pdf.Export(document, stream);
        }
    }
}

Note that if the size of the control is bigger than the size of the page, part of the image may be cropped (similarly to how Word exports large pictures to PDF).

I hope this helps.

Greetings,
Iva Toteva
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
GOURVEZ JJ
Top achievements
Rank 1
answered on 08 Feb 2012, 02:38 PM
Hi,

It's perfect !

Thanks
Tags
Chart
Asked by
GOURVEZ JJ
Top achievements
Rank 1
Answers by
GOURVEZ JJ
Top achievements
Rank 1
Vladimir Milev
Telerik team
Iva Toteva
Telerik team
Share this question
or