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:
<ItemGroup>
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.6"/>
</ItemGroup>For AspEmail.NET, you also need to add the following package reference:
<ItemGroup>
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="4.6"/>
</ItemGroup>Also, the component assembly itself needs to be referenced, for example:
<ItemGroup>
<Reference Include="AspPDF.NET">
<HintPath>bin\Persits.PDF.dll</HintPath>
</Reference>
</ItemGroup>
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
PdfPreview.Save
PdfPreview.SaveToMemory
PdfPreview.SaveHttpSince these methods take advantage of the System.Drawing.Imaging assembly not available in .NET Core, you must instead use the methods
PdfPreview.SaveCore
PdfPreview.SaveToMemoryCore
PdfPreview.SaveHttpCore
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");
...
objDoc.ImportFromUrl(...);