Browse Source

fix runtimes native file path

feature/#16
HueiFeng 5 years ago
parent
commit
1d980e9657
  1. 1
      .gitignore
  2. 1
      src/Magicodes.ExporterAndImporter.Pdf/Magicodes.ExporterAndImporter.Pdf.csproj
  3. 12
      src/Magicodes.ExporterAndImporter.Pdf/PdfExporter.cs

1
.gitignore

@ -260,3 +260,4 @@ paket-files/
__pycache__/
*.pyc
/src/Magicodes.ExporterAndImporter.Excel/Properties/PublishProfiles/FolderProfile.pubxml
/global.json

1
src/Magicodes.ExporterAndImporter.Pdf/Magicodes.ExporterAndImporter.Pdf.csproj

@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props"></Import>
<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;</TargetFrameworks>
<PackageId>Magicodes.IE.Pdf</PackageId>

12
src/Magicodes.ExporterAndImporter.Pdf/PdfExporter.cs

@ -15,7 +15,8 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Diagnostics;
using System.Reflection;
#if NET461
using System.Drawing.Imaging;
@ -53,11 +54,16 @@ namespace Magicodes.ExporterAndImporter.Pdf
// Check the platform and load the appropriate Library
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
var wkHtmlToPdfPath = Path.Combine(Directory.GetCurrentDirectory(), $"runtimes\\linux-x64\\native\\wkhtmltox.so");
var executablePath = Assembly.GetEntryAssembly().Location;
var mainModuleName = Assembly.GetEntryAssembly().ManifestModule.Name;
var currentPath = executablePath.Replace(mainModuleName, "");
var wkHtmlToPdfPath = Path.Combine(currentPath, $"runtimes//linux-x64//native//wkhtmltox.so");
if (!File.Exists(wkHtmlToPdfPath))
{
wkHtmlToPdfPath = Path.Combine(Directory.GetCurrentDirectory(), $"wkhtmltox.so");
wkHtmlToPdfPath = Path.Combine(currentPath, $"wkhtmltox.so");
}
context.LoadUnmanagedLibrary(wkHtmlToPdfPath);
}
}

Loading…
Cancel
Save