无法使用 pdfium 加载 PDF 文件
我正在尝试加载 PDF 文件以使用 pdfium 进行打印。它曾经工作得很顺利,但是一旦我安装了 Docnet.Core(pdfium 的包装器),加载功能就停止工作了。它一直给我这个错误:
Exception thrown: 'System.EntryPointNotFoundException' in PdfiumViewer.dll
System.EntryPointNotFoundException: Unable to find an entry point named 'FPDF_AddRef' in DLL 'pdfium.dll'.
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(Stream stream)
at Project_Receipt.mainPanel.PrintPDF(String printer, Int32 copies, Boolean colored, Stream stream) in C:\Users\alial_he\Source\Repos\JyAli\Project_Receipt\Project_Receipt\Main.cs:line 513
这是打印文件流的函数:
public bool PrintPDF(string printer, int copies, bool colored, Stream stream)
{
try
{
// Create the printer settings for our printer
var printerSettings = new PrinterSettings
{
PrinterName = printer,
Copies = (short)copies,
};
printerSettings.DefaultPageSettings.Color = colored;
IEnumerable<PaperSize> paperSizes = printerSettings.PaperSizes.Cast<PaperSize>();
PaperSize sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4);
printerSettings.DefaultPageSettings.PaperSize = sizeA4;
// Now print the PDF document
using (var document = PdfiumViewer.PdfDocument.Load(stream))
{
using (var printDocument = document.CreatePrintDocument())
{
printDocument.PrinterSettings = printerSettings;
printDocument.PrintController = new StandardPrintController();
printDocument.Print();
}
}
return true;
}
catch (Exception e)
{
string message = "Something went wrong while printing!";
string title = "Printing Error!";
MessageBox.Show(e.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
Debug.WriteLine(e.ToString());
return false;
}
}
有什么建议吗?
I'm trying to load a PDF file to print it using pdfium. It used to work like a charm, but once I installed Docnet.Core (a wrapper for pdfium), the load function stopped working. It keeps giving me this error:
Exception thrown: 'System.EntryPointNotFoundException' in PdfiumViewer.dll
System.EntryPointNotFoundException: Unable to find an entry point named 'FPDF_AddRef' in DLL 'pdfium.dll'.
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(Stream stream)
at Project_Receipt.mainPanel.PrintPDF(String printer, Int32 copies, Boolean colored, Stream stream) in C:\Users\alial_he\Source\Repos\JyAli\Project_Receipt\Project_Receipt\Main.cs:line 513
here is the function that prints the file stream:
public bool PrintPDF(string printer, int copies, bool colored, Stream stream)
{
try
{
// Create the printer settings for our printer
var printerSettings = new PrinterSettings
{
PrinterName = printer,
Copies = (short)copies,
};
printerSettings.DefaultPageSettings.Color = colored;
IEnumerable<PaperSize> paperSizes = printerSettings.PaperSizes.Cast<PaperSize>();
PaperSize sizeA4 = paperSizes.First<PaperSize>(size => size.Kind == PaperKind.A4);
printerSettings.DefaultPageSettings.PaperSize = sizeA4;
// Now print the PDF document
using (var document = PdfiumViewer.PdfDocument.Load(stream))
{
using (var printDocument = document.CreatePrintDocument())
{
printDocument.PrinterSettings = printerSettings;
printDocument.PrintController = new StandardPrintController();
printDocument.Print();
}
}
return true;
}
catch (Exception e)
{
string message = "Something went wrong while printing!";
string title = "Printing Error!";
MessageBox.Show(e.ToString(), title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
Debug.WriteLine(e.ToString());
return false;
}
}
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论