

To do that I have used the following PDF file. In order to do that we need to have a PDF file that we can add to our project. Now that we know what we are doing, let's get to the code: Step 1: Get URL for local PDFĪs I mentioned earlier in this tutorial we will be focussing on how to open a local PDF file. You can also find the full source code for this tutorial here.

Both methods that we are going to use today allows for us to use a URL when trying to load the PDF, so it doesn't matter whether the URL is a local file or not.Įven though this tutorial is not focussed on opening a remote PDF, I will be adding the code at the end of each section that will allow you to open a remote PDF file. If you want to use a hosted file it will work in basically the same way. The PDF can be a local file or a hosted file but we will be using a local file. In this tutorial we explore two ways of opening a PDF file with Swift. It is going to be difficult convincing the higher-ups to pay $3800 for page numbers, but without it we have to resort to crazy hacks (I seriously considered passing the PDF from headless Chrome to LaTeX for page numbers…).PDF files are common place and with iOS/iPadOS becoming a more powerful operating system, opening PDF files and other regular computer type tasks will become more common place. It feels like HTML → print is not an important use case to the standards bodies, and Prince is one of the few renderers that implement HTML+CSS+CSS Paged Media correctly. It is very difficult implementing a renderer for HTML+CSS with a small team, while working on this I had encountered a bug where the PDF text won’t display in Chrome while it does in Firefox.

The samples at are impressive, but they also highlight the inconsistencies among renderers.

Good to hear another happy user of Prince, it was on the top of the list of tools to try until everyone saw the price tag for a commercial license. I never had anything I could not fix (with prince-engine). The rest are the same in both engine.ex and safe.ex besides renaming the modules and html_escape/1 to tex_escape/1Ĭonfig.exs: config :phoenix, :format_encoders, List of escaped characters (taken from PyLaTeX): escapes = [ |> render("invoice.tex", example_invoice) When I look at the output on the browser, the whole template is escaped besides the EEx snippets. DocRaptor and PrinceXML are great solutions but I will need to go through some company process, in the meantime I would like to make EEx work with it.Īnyway I created a format encoder based on the one within Phoenix.HTML and changed the list of escape characters. We had a prototype built with Python3+Jinja2 and I am integrating it into our Phoenix application to simplify the codebase. There are some issues (distro packaging) but in general it went very well, the performance is comparable with headless Chrome yet the output is way better. Page numbers didn’t work either.Īfter investing quite some effort rewriting layout with older CSS and fighting with renderers to get an arguably acceptable output we switched to LaTeX. We are aware of Paged.js and used it with headless Chrome but for some reason it doesn’t work well enough (we need something to stay at a particular page, while break-before/inside/after works, it also creates a massive empty space where an element could fit). There the render finally looks alright but margin boxes aren’t supported. We encountered some issues with it (IIRC it is something about fonts but in general wkhtmltopdf is outdated) and ended up with pupeteer + Chrome. issues on GitHub), we tried pdfkit (a wrapper for wkhtmltopdf). Because of inconsistent renders compared to a browser (IIRC flexbox and tables, cf. We started with HTML → PDF with a prototype using WeasyPrint. Thanks for the reply! I don’t mean to dismiss your solutions but we have tried some of them and unfortunately the results are not very good.
