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?