I have a solution in place for converting html to pdf: html is loaded into a html viewer, printed to pdf with the MBS plugin. Then I add page numbers and a header also with the MBS plugin. Since the change from the HtmlViewer to WKWebViewControlMBS I have had several users with different problems. Either the intermediate file can’t be opened or the final file can’t be written. Neither problem is reproducible. Therefore, I’m looking for a different solution.
WKHtmlToPDF: there is no ARM version and it’s unlikely that one is coming.
Weasyprint (Python): not suitable for my crappy html.
pyhtml2pdf (Python): doesn’t seem very fast. But it was 10times easier to set up than Weasyprint.
Does anyone have other ideas? The html coming from emails is really really bad.
There’s GraffitiHTMLtoPDF, but it’s a Desktop-only solution and – in the currently available version – produces rasterized pages. In the next release of GraffitiSuite it will output proper PDFs that are not rasterized.
For Web, GraffitiPDF has a method for converting HTML to PDF.
If you have a GraffitiSuite account, open a ticket and attach the HTML as a txt file. The next version uses a different engine for the conversion, so it may appear different.
That HTML hits an exception on some of the images being loaded in the new version. That’s probably why the old version was so slow, timeouts on failed image loads.
I don’t think it’ll do what you want. There are server content restrictions that are tripping it up, errors in loading resources, etc. For images in the document that are BASE64, it works flawlessly. URLs, not so much. There’s a lot of security hurdles (especially on macOS) for the HTMLViewer to jump through.
It’s not just the issue of ARM for me, but installed fonts and Android.
I don’t do large PDF files like you, but I created a Xojo web app (server has all needed fonts) that receives the HTML via URLConnection, converts it to PDF (via wkHTMLtoPDF) then returns the PDF to the user. Returns the same exact results whether called from Desktop, Web, Windows, macOS, Linux, iOS or Android!
Not a solution for all, I understand, but it works!
I have 2 main classes of emails: the personal ones with or without attachments. And newsletters which have a lot of resources which may or may not be available.
GraffitiSuite - as it is now - is waayyyyy too slow.
@Christian Schmitz: I know that the problems are not reproducible. Would you take a look again at my problems?
Well, the next version is very fast, but the way it operates isn’t very lenient with outside resources. It was mainly developed to work with GraffitiEditor, which it does quite well.
I’ve stumbled upon another open source tool. It’s basically a super simple console application that works as a wrapper to load an URL into a WebView, then saves the contents as PDF.
Apart from the ReadMe, the Code seems to be about 6 years old… Anyway, I’ve downloaded it. And built it as a macOS Universal binary (x86_64 arm64) and Deployment Target macOS 10.10.
Then I’ve downloaded your test file and tried it. Seems to work just fine.
You could use that source/approach as a “how to build your own dedicated helper” (console application)… strip out unnecessary features, change default parameters, maybe you want to add dedicated parameters for different paper format(s), use the newer WKWebView, whatever.
Anyway - if you’d like to try what I’ve built quickly then you can download the source I’ve downloaded and my “out of the box build” along with your testfile from my Dropbox: Source and Build: URL2PDF Note: The built console application is not codesigned for Distribution… Note 2: I’ll delete this from my Dropbox sooner or later. If someone comes by later, links to the source are provided above.
If you extract it in your Downloads folder, usage would be like this (change paths to reflect your environment…):