Error when trying to export Word Doc to PDF

1 Answer 513 Views
General Discussions PdfProcessing WordsProcessing
Mariner
Top achievements
Rank 1
Mariner asked on 04 Apr 2022, 10:23 PM

I am receiving an error when trying to convert a word doc to a PDF.

 

Here is the code:

var docxPRovider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();

var docBytes = File.ReadAllBytes(path);
var document = docxPRovider.Import(docBytes);

var testFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.pdf");
var resultBytes = pdfProvider.Export(document);
File.WriteAllBytes(testFile, resultBytes);

 

Here is the error:

Could not load type 'System.Windows.Point' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportSettings..ctor()
   at Telerik.Windows.Documents.Flow.FormatProviders.Pdf.Export.PdfExportSettings..ctor()
   at Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider..ctor()

The line in bold is where the error occurs. I verified I have WindowsBase and System.Windows as references in my project.

Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
1
Accepted
Svilen
Telerik team
answered on 05 Apr 2022, 08:11 AM

Hi, Mariner,


My name is Svilen and it would be my pleasure to assist here.

This error most often occurs, when you've used the .NET Framework Nuget package versions in a .NET Core application. Please note that the .NET Standard versions must be used, which do not include Windows in the Nuget Package name. A comparison is available in our Getting Started articles. Here is an example:

Telerik.Windows.Documents.Flow - .NET Framework

Telerik.Documents.Flow - .NET Standard

Please note that this difference is only present in the assembly names. Both versions' namespaces include "Windows". This means that using statements in your classes will contain "Windows" in both cases. The reliable way to confirm, which version you are using is to check your Project > Dependencies > Packages list. Please try replacing the assemblies and let me know if this helps.

I remain at your disposal if further needed.

 

Regards,
Svilen
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/.

Mariner
Top achievements
Rank 1
commented on 05 Apr 2022, 05:32 PM

Yes, that worked. It gets confusing because of the namespace, but I did a proof of concept and then just copied from there. First time Telerik user, so there are hiccups lol.

Thank you!

Svilen
Telerik team
commented on 06 Apr 2022, 07:28 AM

Hello, Mariner,

I am glad to hear my suggestion helped. I hope you have a great experience with our products.

Please do not hesitate to reach out to us should you need any assistance.

Tags
General Discussions PdfProcessing WordsProcessing
Asked by
Mariner
Top achievements
Rank 1
Answers by
Svilen
Telerik team
Share this question
or