Welcome Guest Search | Active Topics | Sign In | Register

Calling HtmlToPdf.ConvertHtml from .NET Core 2.0 Options
Phil
Posted: Tuesday, November 21, 2017 3:01:35 AM
Rank: Advanced Member
Groups: Member

Joined: 11/8/2017
Posts: 66
Hello, I have a .Net Core 2.0 WebApi project with

- TargetFramework of netcoreapp2.0
- I have added EO.Pdf and EO.WebBrowser (v17.3.13) as references using NuGet (which have also added the other two dependencies EO.Base and EO.WebEngine)
- calls HtmlToPdf.ConvertHtml as per below

Quote:
string content = "<html><body>Hello world!</body></html>";
MemoryStream stream = new MemoryStream();
HtmlToPdf.ConvertHtml(content, stream);


The above falls over with "{System.IO.FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.
File name: 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'..."

I have seen your post regarding integration with .Net Core 1.0 (https://www.essentialobjects.com/doc/common/dotnetcore.aspx) however the configuration for .Net Core 2.0 is very different (the contents of project.json is 'translated' into the project file). I've tried to translate what you have within the 1.0 article (with numerous variations) and have been unsuccessful

I've also tried separating the call to HtmlToPdf.ConvertHtml into a another project targeting net461 and/or netstandard2.0 but to no avail (I get the message "{System.IO.FileNotFoundException: Could not load file or assembly 'EO.Pdf, Version=17.3.13.0, Culture=neutral, PublicKeyToken=e92353a6bf73fffc'. The system cannot find the file specified.
File name: 'EO.Pdf, Version=17.3.13.0, Culture=neutral, PublicKeyToken=e92353a6bf73fffc'..." or a message suggesting version conflict)

Are you able to explain how this is done (i.e. calling HtmlToPdf.ConvertHtml from within a .Net Core 2.0 project)
eo_support
Posted: Tuesday, November 21, 2017 11:19:06 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Thanks for bring this to our attention. We have not visited .NET 2.0 support yet. We will look into this and see if it can be supported (still just compile time, not runtime) and update our documentation accordingly.
eo_support
Posted: Thursday, November 23, 2017 8:37:13 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,221
Hi,

We have looked into this. As with .NET Core 1.1, you will NOT be able to run EO.Pdf on .NET Core. The document provided for .NET Core 1.1 is only allow you to build your application on .NET Core (for example, for project maintenance purpose). For .NET Core 2.0 it will be the same. You will be able to build it with .NET Core 2.0 but you won't be able to run it.

You can follow these steps to modify your .NET Core 2.0 project to target .NET Framework:

1. Open your .NET Core 2.0 project in Visual Studio (requires 2017.15.3 and newer);
2. Open solution Explorer, right click your project, then select "Edit your_project_file", here your_project_file is the project file name, for example, Test.csproj. This will open the project file in XML Editor;
3. Modify the following tag:

Code: XML
<TargetFramework>netcoreapp2.0</TargetFramework>


To:

Code: XML
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>


Note that:

a. TargetFramework becomes TargetFrameworks;
b. net461 has been added into the list. You can use other frameworks too, for example, net45;

Save the changes and Visual Studio should reload the project;

4. You can now add our DLL references the same way as you do with a .NET Framework project:

https://www.essentialobjects.com/doc/common/refdll.aspx

Now you will be able to build the project both as .NET Core and .NET Framework. However you will still only be able to run it on .NET Framework.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!



You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.