Convert Word to PDF

14 posts, 1 answers
  1. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 15 Aug 2019 Link to this post

    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);

     

     

  2. Martin
    Admin
    Martin avatar
    46 posts

    Posted 16 Aug 2019 Link to this post

    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.
  3. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 16 Aug 2019 in reply to Martin Link to this post

    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

  4. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 16 Aug 2019 in reply to Naveen Link to this post

    attaching the screenshot of the suggestions i get in visual studio
  5. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 16 Aug 2019 in reply to Martin Link to this post

    another screenshot, that shows the PDF library is missing.
  6. Martin
    Admin
    Martin avatar
    46 posts

    Posted 21 Aug 2019 Link to this post

    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.
  7. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 21 Aug 2019 in reply to Martin Link to this post

    The version of telerik that i have installed in my computer is : version 2019.2.514
  8. Martin
    Admin
    Martin avatar
    46 posts

    Posted 23 Aug 2019 Link to this post

    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.
  9. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 23 Aug 2019 in reply to Martin Link to this post

    Hi Martin

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

  10. Martin
    Admin
    Martin avatar
    46 posts

    Posted 26 Aug 2019 Link to this post

    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.
  11. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 26 Aug 2019 in reply to Martin Link to this post

    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.

  12. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 26 Aug 2019 in reply to Martin Link to this post

    attaching the screenshot
  13. Answer
    Martin
    Admin
    Martin avatar
    46 posts

    Posted 28 Aug 2019 Link to this post

    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.
  14. Naveen
    Naveen avatar
    12 posts
    Member since:
    Aug 2019

    Posted 09 Sep 2019 in reply to Martin Link to this post

    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.

Back to Top