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

How do I put a WPF Xaml UserControl in the PDFViewer

3 Answers 327 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Joe asked on 06 Jan 2020, 08:59 PM

I'm trying to use RadPdfViewer in my WPF app but it seems unwieldy.  I am wondering if I misunderstand it.

With the normal WPF DocumentViewer and FixedDocument, I can lay out a page in XAML just as I want it and then just add that the the FixedDocument.  Can I do this with RadPdfViewer?   

Every example I see (in the PdfProcessing examples) has the user creating text blocks, tables and annotations in code-behind and then individually adding them to RadFixedPages.  That completely defeats the purpose of using WPF in the first place.  I don't want to lay out a report in code-behind.  I want to lay out out a XAML page and add it to the report.

But since this stuff comes with your UI for WPF, I assume I must be missing something fundamental.

To be explicit, here is what I do right now when the user tries to generate a report. 

  • I start off with a view model "PageVm"
  • The main report is laid out in ReportView.xaml .
  • I've already laid out my report pages with ReportPageView.xaml

 

// Code behind of ReportView.xaml.cs
         
private void GenerateViewerDoc(ReportPageVm page,Vm Size pageSize)
{

     // Create the document, PageView

    var doc = new FixedDocument();
    var rc = new ReportPageView { DataContext    = pageVm  };
    doc.DocumentPaginator.PageSize = pageSize;
    var content = new PageContent() { DataContext = pageVm };
 
    var page = new FixedPage  {  DataContext = pageVm };
 
    page.Children.Add(rc);
    ((IAddChild)content).AddChild(page);
    doc.Pages.Add(content);
             
     // Put this new document into the Document Viewer (which is declared in XAML)
     Viewer.Document = doc;
 }

 

Is this possible with Telerik's UI?  How do I do it?

 

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 07 Jan 2020, 01:49 PM

Hello Joe,

I understand your concerns. Unfortunately, RadPdfViewer is not intended to work this way. Its functionality is mostly focused to display already created PDF files from various sources. What I can suggest is converting the XAML to a pdf file which later can be displayed in RadPdfViewer. We have an example that shows how this can be achieved in our sdk-repository: document-processing-sdk/PdfProcessing/ExportUIElement at master ยท telerik/document-processing-sdk.

Let me know how this works for you.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 07 Jan 2020, 03:34 PM
Thanks, Dimitar,

I did actually try the method laid out in that sample.  In fact I spent a whole lot of time trying to take all of that code and bring it into my project.  The approach appears to be to try to create an analog of every possible WPF element (Text, image, Line, etc) as a "concrete renderer" that can put it into PDF.  It's ambitious and sort-of works but is unfortunately not complete.  I have done far too much work on my UI controls to have them render a specific way and simply could not replicate it using that method.  After many changes and much frustration I was getting nowhere and had to abandon it.

What I have with the normal DocumentViewer works well enough I guess.  I was just hoping for the typical improvement I find in other UI-for-WPF stuff.
0
Accepted
Dimitar
Telerik team
answered on 08 Jan 2020, 09:04 AM

Hi Joe,

I am sorry that our control does not fit in your scenario. I cannot think of an alternative solution with RadPdfViewer or other control for this case. Nevertheless, should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
PDFViewer
Asked by
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dimitar
Telerik team
Joe
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or