'How to convert html to pdf on an arm32 without installing wkhtmltopdf
I am trying to convert html documents to pdfs on an arm32 (NXP i.MX6 ARM Cortex A9). I am writing the application in C# as an .NetCore application. The problem I have is that none of the things I've tried work and I have yet to find a solution to why.
I have tried to use several external libraries to do this, most of which only work for Windows according to their support teams, so the reason they don't work is obvious (eg EvoPdf, SelectPdf, HiQPdf and others). The ones I have tried that I think should work for linux are Ironpdf, wrappers to wkHtmlToPdf (OpenHtmlToPdf, SharkPdf etc), pdfTron and headless chrome. They all give different errors:
Ironpdf complains that the libraries are not installed (I have emailed their support so they might solve this). The IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true is set in my code but I still get the error telling me to set it to true.
One or more errors occurred. (The Docker or Linux image is missing dependencies for IronPDF.
Please read https://ironpdf.com/docs/questions/docker-linux/
You may alternatively set IronPdf.Installation.LinuxAndDockerDependenciesAutoConfig = true to automatically resolve this issue.)
OpenHtmlToPdf has wkHtmlToPdf included but it gives a Permission Denied Error.
at Interop.Sys.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setUser, UInt32 userId, UInt32 groupId, Int32& lpChildPid, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean shouldThrow)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at OpenHtmlToPdf.HtmlToPdfConverterProcess.Convert(ConversionSource conversionSource)
at OpenHtmlToPdf.Pdf.DocumentBuilder.ReadContentUsingTemporaryFile(String temporaryFilename)
at OpenHtmlToPdf.Pdf.DocumentBuilder.Content()
at OpenHTML2pdf.Program.Main(String[] args) in
wkHtmlToPdf-wrappers with wkHtmlToPdf externally says it can't find wkHtmlToPdf (I can't install it so this one is obvious why it doesn't work)
pdfTron says it can't load one of the libraries it uses.
Unhandled Exception: System.DllNotFoundException: Unable to load shared library 'PDFNetC' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libPDFNetC: cannot open shared object file: No such file or directory
at pdftron.PDFNetPINVOKE.TRN_PDFDocCreate(IntPtr& doc)
at pdftron.PDF.PDFDoc..ctor()
Headless chrome gives a navigation error but it should find the correct file.
$ chromium-browser --headless --disable-gpu --print-to-pdf=file1.pdf --no-margins file1.html
[0930/085730.493897:WARNING:audio_manager.cc(295)] Multiple instances of AudioManager detected
[0930/085730.494843:WARNING:audio_manager.cc(254)] Multiple instances of AudioManager detected
[0930/085730.514971:ERROR:headless_shell.cc(100)] Navigation to failed
Does anyone have a solution to any of these errors or a tip about something to use that might work? I feel like I can't get any further on my own.
Solution 1:[1]
Macports has a wkhtmltopdf arm64 port for the Mac M1 machines. Perhaps you could adapt their build script to arm32. https://ports.macports.org/port/wkhtmltopdf/details/
For my label printing usage, wkhtmltopdf doesn't generate very accurate results. I've resorted to creating a c# wrapper for libHaru (http://libharu.org/) to generate pdf's directly.
Recently I've spotted nuget package Haru.Net, https://www.nuget.org/packages/Haru.Net From the Readme: "Libharu (Haru FREE PDF Library) .NET wrapper for net451+ and netstandard2.0 (including netcore). The package consists of precompiled binaries for win32, win64, linux64 (tested on CentOS 7) linux arm32, linux arm64 and MacOS."
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ziggy90127 |
