-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQpdfWrapper.cs
More file actions
42 lines (35 loc) · 1.42 KB
/
QpdfWrapper.cs
File metadata and controls
42 lines (35 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace NativeQpdf;
public class QpdfWrapper
{
private const string BinaryPath = "libqpdf.29";
[DllImport(BinaryPath, CallingConvention = CallingConvention.Cdecl,
EntryPoint = "qpdfjob_run_from_json")]
public static extern int RunFromJSON(
[MarshalAs(UnmanagedType.LPStr)] string json);
[ModuleInitializer]
internal static void Initialize()
{
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), (libraryName, assembly, searchPath) =>
{
if (libraryName == BinaryPath)
{
var isArm = RuntimeInformation.OSArchitecture == Architecture.Arm64;
var isOsx = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
var isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
if (isLinux && isArm)
{
return NativeLibrary.Load("runtimes/linux-arm64/native/" + BinaryPath + ".so", assembly, default);
}
else if (isOsx && isArm)
{
return NativeLibrary.Load("runtimes/osx-arm64/native/" + BinaryPath + ".dylib", assembly, default);
}
return NativeLibrary.Load(BinaryPath, assembly, default);
}
return default;
});
}
}