无法使用 pdfium 加载 PDF 文件

发布于 01-19 22:07 字数 2488 浏览 3 评论 0原文

我正在尝试加载 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文