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

What objects to use for bringing RTF, PDF, etc. files into document flow

8 Answers 351 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Darrell
Top achievements
Rank 1
Darrell asked on 08 Oct 2020, 03:31 PM

Hi all,

My company has historically used an ActiveX control to produce certain documents, created as PDFs, for printing or sending via email. With the move to a new development environment we lost support for ActiveX and need to switch to the Telerik document controls.

We wrote a program using the following Telerik objects:

Telerik.Windows.Documents.Fixed.Model.RadFixedDocument.

Telerik.Windows.Documents.Fixed.Model.RadFixedPage.

Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor.

This works fine for most of the document creation, but we have a need  to add language specific to each of our customers to the document. This language comes from each customer in an RTF file. The old control had a method to add the RTF file to the document flow, and it used the RTF metadata to add the properly formatted text to the document. Can you tell me if the Telerik document model has the ability to do this? And what objects/methods would be best to use? If it doesn't support RTF specifically, but has this ability for other formats, I can convert the RTF file to PDF, DOCX, etc.  Thanks.

8 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 09 Oct 2020, 11:12 AM

Hi Darrell,

You can import an RTF document into a RadFlowDocument model using the RtfFormatProvider of the WordsProcessing library. More information and examples you can find in the Using RtfFormatProvider help article.

I hope this helps. Do not hesitate to contact us if any additional questions arise.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Darrell
Top achievements
Rank 1
answered on 09 Oct 2020, 01:35 PM
Thank you Martin.  I'll check it out and let you know if I have any more questions.
0
Martin
Telerik team
answered on 12 Oct 2020, 05:37 AM

Hello Darrell,

Take your time for testing and if you have any difficulties, please let us know.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Darrell
Top achievements
Rank 1
answered on 12 Oct 2020, 03:25 PM

Our existing program was written using the RadFixedDocument object.  I think that was because the ultimate goal was to produce a PDF, as I see that RadFixedDocument is part of RadPDFProcessing library.  Using your suggestion of the RadFlowDocument, would I have to change all of the existing code to use that as well?  Sorry, I am not at all familiar with these libraries.

If that's the case, is there a way to import a different type of file into the RadFixedDocument flow?  As mentioned, I can convert the RTF file to a PDF, DOCX, etc.  I really don't want to have to rewrite the program to use a different library if I don't have to.

0
Martin
Telerik team
answered on 13 Oct 2020, 10:18 AM

Hi Darrell,

You can use at the same time both RadFIxedDocument and RadFlowDocument and you don't need to change all the existing code. You will only need to extend it with the import of the RTF file into a RadFlowDocument and then export it to RadFixedDocument logic.

As a side note, the RadFlowDocument model provides you with the opportunity to import the following formats into a RadFlowDocument which later can be easily exported to RadFixedDocument (or PDF file):

However, if you decide not to use the RadFlowDocument model in your code, you can convert the documents to PDF files and then import them with the PdfProcessing`s PdfFormatProvider directly into a RadFixedDocument.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Darrell
Top achievements
Rank 1
answered on 13 Oct 2020, 03:14 PM
Sounds good.  Thanks Martin.
0
Darrell
Top achievements
Rank 1
answered on 11 Dec 2020, 06:43 PM

Hi Martin,

I noticed in the two links that you referenced on importing and exporting that the export link takes you to the documentation on the PdfFormatProvider.  Since we're working with RTF files, is that what you intended? 

I tried to find a similar method to PdfFormatProvider.ExportToFixedDocument in the RTF library, but couldn't.

0
Martin
Telerik team
answered on 15 Dec 2020, 09:59 AM

Hi Darrell,

I order to export a convert an RTF file to a RadFixedDocument you will need to:

  1. use the WordsProcessing`s RtfFormatProvider to import the RTF into a RadFlowDocument.
    RadFlowDocument document;
    RtfFormatProvider rtfFormatProvider = new RtfFormatProvider();
    using (Stream input = File.OpenRead("SampleDocument.rtf"))
    {
    	document = rtfFormatProvider.Import(input);
    }
  2. use the WordsProcessing`s PdfFormatProvider to export this RadFlowDocument to a RadFixedDocument.
    Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider pdfFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
    RadFixedDocument fixedDocument = pdfFormatProvider.ExportToFixedDocument(document);

I am attaching a sample project demonstrating this functionality as well.

As a side note, I want to clarify there are two different PdfFormatProviders:

  1. The first one is from the WordsProcessing library and it allows you to export a RadFlowDocument to RadFixedDocument or directly to a PDF file.
  2. The second one is part of the PdfProcessings library and it allows you to import a PDF file into a RadFixedDocument and vise versa.

Regards,
Martin
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
General Discussions
Asked by
Darrell
Top achievements
Rank 1
Answers by
Martin
Telerik team
Darrell
Top achievements
Rank 1
Share this question
or