Replacement for PDFDocumentSource?

1 Answer 80 Views
PDFViewer
Johnathan
Top achievements
Rank 1
Iron
Iron
Johnathan asked on 06 Jun 2024, 09:26 PM

   I have a PDF file that's been imported into a MemoryStream object and now I need to display it using the Telerik UI for WPF pdfViewer control.  The existing documentation says that you can create a PdfDocumentSource object and bind the pdfViewer.DocumentSource to that.  However, either PdfDocumentSource no longer exists, or I can't figure out what the correct Namespace is.

   I'm using TelerikUI for WPF v2024 Q2.  However changelogs for 2020 (https://docs.telerik.com/devtools/wpf/controls/radpdfviewer/changes-and-backward-compatibility/backward-compatibility)  say that: 

Changed
Obsolete constructors of Telerik.Windows.Documents.Fixed.PdfDocumentSource:

PdfDocumentSource(Uri uri, FormatProviderSettings settings)
PdfDocumentSource(Stream stream, FormatProviderSettings settings)
What to do now
Use the overloads that accept Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.PdfImportSettings instead.

   I've also read that there is some kind of merge going on trying to replace the previous PDF code with Telerik.Windows.Documents.Fixed .  In any case, I can't seem to figure out how to go from a MemoryStream to something that the pdfViewer.DocumentSource likes.  

   Can anyone help with a very basic code sample to take a PDF as a memorystream and create something that pdfView.DocumentSource will accept?  Thank you!

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 07 Jun 2024, 07:49 AM

Hi Johnathan,

Directly passing the memory stream works on my side. Here is an example: 

var bytes = File.ReadAllBytes("..\\..\\..\\lorem.pdf");
var str = new MemoryStream(bytes);
this.pdfViewer.DocumentSource = new PdfDocumentSource(str);

Another approach is to directly set the document: 

var bytes = File.ReadAllBytes("..\\..\\..\\lorem.pdf");
var str = new MemoryStream(bytes);
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(str);
pdfViewer.Document = document;

I hope this helps. Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Johnathan
Top achievements
Rank 1
Iron
Iron
commented on 07 Jun 2024, 04:46 PM

Thank you Dimitar!  Where do you get PdfDocumentSource?  Documentation (https://docs.telerik.com/devtools/wpf/api/telerik.windows.documents.fixed.pdfdocumentsource) says it's TELERIK.WINDOWS.DOCUMENTS.FIXED, however it doesn't appear to be there anymore:

Dimitar
Telerik team
commented on 10 Jun 2024, 07:10 AM

Hi Johnathan,

The assembly is Telerik.Windows.Controls.FixedDocumentViewers. On the left side, you can see the namespace. The assembly is at the bottom (see attached). 

Let me know if I can be of further assistance.

 

Johnathan
Top achievements
Rank 1
Iron
Iron
commented on 29 Jun 2024, 08:38 PM

Thank you very much Dimitar!
Tags
PDFViewer
Asked by
Johnathan
Top achievements
Rank 1
Iron
Iron
Answers by
Dimitar
Telerik team
Share this question
or