Persits Software, Inc. Knowledge Base Articles

Using .NET Components with .NET Core on Windows and Linux

Problem Summary

This article describes what needs to be done to run AspPDF.NET, AspEmail.NET and AspJpeg.NET with Microsoft .NET Core on Windows and Linux.


1. Registration Key (Windows & Linux)

Normally, the registration key for our native .NET components is placed in the .config file of the application. Since .NET Core does not use .config files, the registration key must be specified directly in the script file, for example:

PdfManager objPDF = new PdfManager();
objPDF.RegKey = "GYlbv+................5u+jNHrru";

2. Changes in the Project File (Windows & Linux)

Since all our native .NET components reference the System.Configuration.ConfigurationManager assembly, and by default this assembly is not present in a .NET Core application, it needs to be referenced in the Project file as follows:

   <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6"/>

For AspEmail.NET, you also need to add the following package reference:

   <PackageReference Include="System.Security.Cryptography.Pkcs" Version="4.6"/>

Also, the component assembly itself needs to be referenced, for example:

   <Reference Include="AspPDF.NET">

3. AspPDF.NET's PDF-to-Image Functionality (Windows & Linux)

Normally, the image obtained from PDF-to-Image conversion is saved to disk, memory or HTTP stream via the methods


Since these methods take advantage of the System.Drawing.Imaging assembly not available in .NET Core, you must instead use the methods


4. AspPDF.NET's Use of TrueType Fonts (Linux Only)

When run on Windows, AspPDF.NET uses the systen registry to obtain the locations of the TrueType font files on the system. On Linux, AspPDF.NET does not know where the TrueType fonts are. Therefore, you must explicitly load the font files via the method objDoc.Fonts.LoadFromFile. The indexer objDoc.Fonts[] must not be used.

For example:

PdfFont objFont = objDoc.Fonts.LoadFromFile("fonts/times.ttf");
objPage.Canvas.DrawText( "Text", "x=0; y=200", objFont );

When using the ImportFromUrl method, all the fonts used by the HTML document being imported need to be loaded before calling ImportFromUrl. You must always load the Times New Roman font because it is the default font. You should also load the bold, italic, and bold/italic versions of the fonts as well, for example:

PdfFont objF1 = objDoc.Fonts.LoadFromFile("fonts/times.ttf");
PdfFont objF2 = objDoc.Fonts.LoadFromFile("fonts/timesbd.ttf");
PdfFont objF3 = objDoc.Fonts.LoadFromFile("fonts/timesi.ttf");
PdfFont objF4 = objDoc.Fonts.LoadFromFile("fonts/timesbi.ttf");