TextBox export to PDF

7 posts, 0 answers
  1. GOURVEZ JJ
    GOURVEZ JJ avatar
    55 posts
    Member since:
    Dec 2009

    Posted 30 Jan 2012 Link to this post

    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
  2. GOURVEZ JJ
    GOURVEZ JJ avatar
    55 posts
    Member since:
    Dec 2009

    Posted 01 Feb 2012 Link to this post

    Nobody ???
  3. DevCraft banner
  4. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 02 Feb 2012 Link to this post

    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 >>

  5. GOURVEZ JJ
    GOURVEZ JJ avatar
    55 posts
    Member since:
    Dec 2009

    Posted 02 Feb 2012 Link to this post

    Thanks for your answer.
    But I want export to PDF.
    Does it possible ?
    Thanks
  6. GOURVEZ JJ
    GOURVEZ JJ avatar
    55 posts
    Member since:
    Dec 2009

    Posted 07 Feb 2012 Link to this post

    Hi,

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

    Thanks
  7. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 07 Feb 2012 Link to this post

    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 >>
  8. GOURVEZ JJ
    GOURVEZ JJ avatar
    55 posts
    Member since:
    Dec 2009

    Posted 08 Feb 2012 Link to this post

    Hi,

    It's perfect !

    Thanks
Back to Top
DevCraft banner