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

Convert Word to PDF

13 Answers 1721 Views
WordsProcessing
This is a migrated thread and some comments may be shown as answers.
Naveen
Top achievements
Rank 1
Naveen asked on 15 Aug 2019, 10:01 PM

I have a word doc that i created using RadFlowDocument and i want to convert this to a pdf. i have tried couple of ways and it never worked.

 

        'Exporting the Rad Document to Word Document
        Using output As Stream = File.OpenWrite(directoryPath + "FlexFab.docx")
            Dim provider As DocxFormatProvider = New DocxFormatProvider()
            provider.Export(document, output)
        End Using

        'Convert word to PDF
        Dim fileFormatProvider As IFormatProvider(Of RadFlowDocument) = New DocxFormatProvider()
        Using input As FileStream = New FileStream(filePath, FileMode.Open)
            document = fileFormatProvider.Import(input)
        End Using
        fileFormatProvider = New PdfFormatProvider()
        Using output2 As Stream = New FileStream(directoryPath + "FlexFab.pdf", FileMode.OpenOrCreate)
            fileFormatProvider.Export(document, output2)
        End Using

 

 

The Error that i am getting is :

Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider' to type 'Telerik.Windows.Documents.Common.FormatProviders.IFormatProvider`1[Telerik.Windows.Documents.Flow.Model.RadFlowDocument]'.

 

 

 

I also tried the below method and that dosent work either, is there a way i can achieve this.

Dim document  As RadFlowDocument = CreateRadFlowDocument

Dim provider Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
Dim fixedDocument  As RadFixedDocument = provider.ExportToFixedDocument(document);

 

 

13 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 16 Aug 2019, 03:34 PM
Hello Naveen,

The reason for such a behavior might be the usage of improper namespaces. When you are exporting a RadFlowDocument (DOCX, RTF, HTML or plain text) you will need to use RadWordsProcessing`s PdfFormatProvider with its reference to Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll. Can you please verify the required assemblies are referenced in the project and the correct imports are added?. The Using PdfFormatProvider topic lists the prerequisites for using the export to PDF functionality.

Additionally, you might find helpful to check the examples in our SDK repository which show several usages of the library.

I hope this helps. Please, let me know if there is anything else I can assist you with.

Regards,
Martin
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
Naveen
Top achievements
Rank 1
answered on 16 Aug 2019, 05:12 PM

Yes i did try using the correct namespace and this is what happens every time i import the dll.

looks like the dll file dose not have the pdf library in it. Attaching the screenshot

0
Naveen
Top achievements
Rank 1
answered on 16 Aug 2019, 05:16 PM
attaching the screenshot of the suggestions i get in visual studio
0
Naveen
Top achievements
Rank 1
answered on 16 Aug 2019, 06:15 PM
another screenshot, that shows the PDF library is missing.
0
Martin
Telerik team
answered on 21 Aug 2019, 01:44 PM
Hi Naveen,

What I am assuming is that still there is a mismatch in the references. For better analysis of this behavior, could I ask you to send us a screenshot of the DLLs referenced in the project? I verified the case and everything seems to be working as expected on our side. 

Regards,
Martin
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
Naveen
Top achievements
Rank 1
answered on 21 Aug 2019, 08:34 PM
The version of telerik that i have installed in my computer is : version 2019.2.514
0
Martin
Telerik team
answered on 23 Aug 2019, 02:09 PM

Hi Naveen,

Everything seems fine, except that in the provided screenshot I didn't see Telerik.Windows.Documents.Flow.FormatProviders.Pdf.dll. This should be the reason for the messages of the missing library. Please, make sure to include the missing reference to your project and let me know if you are still experiencing issues.

Regards,

Martin

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
Naveen
Top achievements
Rank 1
answered on 23 Aug 2019, 08:31 PM

Hi Martin

Can you tell me how to do that? How can i add the missing reference to my project?

0
Martin
Telerik team
answered on 26 Aug 2019, 04:05 PM

Hello Naveen,

First thing you will need to do is to install the Telerik bundles which includes the Telerik Document Processing. After creating a project in Visual Studio in Solution Explorer window right-click on the References and search for required DLL in the Assemblies >> Extensions (see AddReferenceScreenshot). Find Telerik.Windows.Documents.Flow.FormatProviders.Pdf (or any other Document Processing DLL), select it and click OK (see ReferenceManagerScreenshot). The assembly should now appear in your references.

Regards,
Martin
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
Naveen
Top achievements
Rank 1
answered on 26 Aug 2019, 04:32 PM

Hi Martin,

 

I have been doing that from the beginning, the problem here is i dont see the Telerik.Windows.Documents.Flow.FormatProviders.Pdf within the Telerik.Windows.Documents.Flow.FormatProviders.

It is missing, i also checked the DLL file in the bin folder and it dose not have it either, see the screenshot i have attached here, also refer to other screenshots i have attached in this conversation.

0
Naveen
Top achievements
Rank 1
answered on 26 Aug 2019, 04:32 PM
0
Accepted
Martin
Telerik team
answered on 28 Aug 2019, 01:00 PM

Hello Naveen,

The first thing I would like to point out to your attention is that the Telerik.Windows.Documents.Flow.FormatProviders.Pdf is not part of the Telerik.Windows.Documents.Flow.FormatProviders namespace, but it is a separate assembly, which must be referenced from the project’s references.

A possible solution of the case could be firstly in the Project Designer to click the References tab (as I saw from the screenshot you already did), then click on the Add button (screenshot1). Next, you will need to search and add the required DLL in the Assemblies >> Extensions (screenshot2). If you found the missing DLL, you could see it now in the project References (screenshot3 & screenshot4). For more information please check How to: Add or remove imported namespaces and Manage references in a project help topics.

Regards,
Martin
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
Naveen
Top achievements
Rank 1
answered on 09 Sep 2019, 05:10 PM

Hi Martin,

I was thinking that Telerik.Windows.Documents.Flow.FormatProviders.Pdf is part of the Telerik.Windows.Documents.Flow.FormatProviders namespace. Thank you very much for being very patient with me through out the conversation. I did try what u said and it works now.

Thank You again.

Tags
WordsProcessing
Asked by
Naveen
Top achievements
Rank 1
Answers by
Martin
Telerik team
Naveen
Top achievements
Rank 1
Share this question
or