You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I spent hours trying to find a .Net 8 compatible way to print an existing PDF file that didn't require licensing. Something I thought was super simple, but isn't. This is where I ended up and I came here with low expectations. I am now very pleased that it works perfectly for my needs (Windows environment, .Net (Core)). Thank you for this.
I did run into an issue that required me to manually patch the code with a minor change. My application utilizes Microsoft ClickOnce for deployment, and in my case I am deploying framework Independent. It seems with ClickOnce, when you build framework independent, it puts your dependency files into the application folder (.\pdfium.dll) and not into a separate .\runtimes\win-x64\native\pdfium.dll folder as assumed in the code. This triggers the following exception:
throw new FileNotFoundException($"Native Library not found in path {path} or {Path.Combine(assemblySearchPath, fileName)}. " +
$"Verify you have included the native Pdfium library in your application, " +
$"or install the default libraries with the bblanchon.PDFium NuGet.");
I have a fix that seems to work for me. Unfortunately, I'm not a git user, so creating a pull request is a big ask, but I thought I'd share what worked for me without breaking the original code.
In PdfiumPrinter.LibraryLoader.NativeLibraryLoader.LoadNativeLibrary look for where it checks for !File.Exists(path). Replace that block with this...
if (!File.Exists(path))
{
var libFound = Directory.EnumerateFiles(assemblySearchPath, fileName, SearchOption.TopDirectoryOnly).SingleOrDefault();
if (!string.IsNullOrEmpty(libFound))
path = libFound;
else
throw new FileNotFoundException($"Native Library not found in path {path} or {Path.Combine(assemblySearchPath, fileName)}. " +
$"Verify you have included the native Pdfium library in your application, " +
$"or install the default libraries with the bblanchon.PDFium NuGet.");
}
Alternatively, and I don't see this documented anywhere, it appears that maybe you could also call the static PdfiumPrinter.PdfLibrary.EnsureLoaded(pathToNativePDFiumDLL); to preset it explicitly to the location of your choice. This should work, but doesn't automatically adjust to different build types.
I hope this is helpful to someone else.
The text was updated successfully, but these errors were encountered:
I spent hours trying to find a .Net 8 compatible way to print an existing PDF file that didn't require licensing. Something I thought was super simple, but isn't. This is where I ended up and I came here with low expectations. I am now very pleased that it works perfectly for my needs (Windows environment, .Net (Core)). Thank you for this.
I did run into an issue that required me to manually patch the code with a minor change. My application utilizes Microsoft ClickOnce for deployment, and in my case I am deploying framework Independent. It seems with ClickOnce, when you build framework independent, it puts your dependency files into the application folder (.\pdfium.dll) and not into a separate .\runtimes\win-x64\native\pdfium.dll folder as assumed in the code. This triggers the following exception:
I have a fix that seems to work for me. Unfortunately, I'm not a git user, so creating a pull request is a big ask, but I thought I'd share what worked for me without breaking the original code.
In PdfiumPrinter.LibraryLoader.NativeLibraryLoader.LoadNativeLibrary look for where it checks for !File.Exists(path). Replace that block with this...
Alternatively, and I don't see this documented anywhere, it appears that maybe you could also call the static
PdfiumPrinter.PdfLibrary.EnsureLoaded(pathToNativePDFiumDLL);
to preset it explicitly to the location of your choice. This should work, but doesn't automatically adjust to different build types.I hope this is helpful to someone else.
The text was updated successfully, but these errors were encountered: