Export UIElement to PDF in Silverlight

2 posts, 0 answers
  1. Bjorn
    Bjorn avatar
    6 posts
    Member since:
    Nov 2010

    Posted 03 Aug 2011 Link to this post

    Hi,

    I did some searching through your website and some googling but i can't find a proper answer.

    I think i saw an example once where you could export an UIElement as PDF in Silverlight using the Export library (?!)

    is this true? If so, could you point me to this example or otherwise indicate if this is possible and give some pointers to look at?

    Thanks!
  2. Bjorn
    Bjorn avatar
    6 posts
    Member since:
    Nov 2010

    Posted 03 Aug 2011 Link to this post

    I found it.

    http://www.telerik.com/help/silverlight/radrichtextbox-features-import-export.html

    together with

    http://www.telerik.com/help/silverlight/radrichtextbox-features-document-elements-raddocument.html

    showed me how to do it.

    here is a code snippit:

    private void PrintToPDF()
    {
        Section section = new Section();
        Paragraph paragraph = new Paragraph();
        InlineUIContainer container = new InlineUIContainer();
        container.UiElement = new PrintLayout(this.map);
        container.Height = 400;
        container.Width = 400;
        paragraph.Inlines.Add(container);
        section.Blocks.Add(paragraph);
        RadDocument document = new RadDocument();
        document.DefaultPageLayoutSettings = new PageLayoutSettings(PaperTypes.Letter);
        document.Children.Add(section);
        PdfFormatProvider provider = new PdfFormatProvider();
        string extension = "pdf";
        SaveFileDialog dialog = new SaveFileDialog()
        {
            DefaultExt = extension,
            Filter = String.Format("{1} file (*.{0})|*.{0}|All files (*.*)|*.*", extension, "PDF"),
            FilterIndex = 1
        };
        bool? dialogResult = dialog.ShowDialog();
        if (dialogResult == true)
        {
            using (Stream output = dialog.OpenFile())
            {
                provider.Export(document, output);
                MessageBox.Show("Saved Successfuly!");
            }
        }
    }
Back to Top