我尝试使用 pdfium 将 pdf 转换为 linux 中的图像。但收到此错误:
Unhandled exception. System.DllNotFoundException: Unable to load shared library 'pdfium.dll' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libpdfium.dll: cannot open shared object file: No such file or directory
at PdfiumViewer.NativeMethods.Imports.FPDF_AddRef()
at PdfiumViewer.NativeMethods.FPDF_AddRef()
at PdfiumViewer.PdfLibrary..ctor()
at PdfiumViewer.PdfLibrary.EnsureLoaded()
at PdfiumViewer.PdfFile..ctor(Stream stream, String password)
at PdfiumViewer.PdfDocument..ctor(Stream stream, String password)
at PdfiumViewer.PdfDocument.Load(Stream stream, String password)
at PdfiumViewer.PdfDocument.Load(String path, String password)
at PdfiumViewer.PdfDocument.Load(String path)
at PDFiumOnLinux.Program.Main(String[] args) in /src/Program.cs:line 10
这是我的源代码:
using PdfiumViewer;
using System.Drawing.Imaging;
namespace PDFiumOnLinux
{
class Program
{
static void Main(string[] args)
{
using (var pdfDocument = PdfDocument.Load(@"Test.pdf"))
{
var bitmapImage = pdfDocument.Render(0, 300, 300, true);
bitmapImage.Save(@"Test.jpg", ImageFormat.Jpeg);
}
}
}
}
这是 csporj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PdfiumViewer" Version="2.13.0" />
<PackageReference Include="PDFiumCore" Version="4503.0.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
</ItemGroup>
</Project>
这是 docker-compose 文件:
version: "3.9"
services:
app:
image: mcr.microsoft.com/dotnet/sdk:3.1.409-buster
volumes:
- .:/src
working_dir: /src
entrypoint: bash -c "dotnet build PDFiumOnLinux.csproj && dotnet bin/Debug/netcoreapp3.1/PDFiumOnLinux.dll"
该程序可以使用以下命令运行:
docker-compose run --rm app
我尝试了其他库,例如“PDFium.LinuxV2”或“PDFium.Linux.x64”而不是“PDFiumCore”,但没有进行任何更改。