Update to iOS Html to Pdf Conversion
My previous post on how to convert or print UIWebView / html / url to pdf has generated a ton of traffic to my site. Lots of Google searches hit my site. I have always wanted to update this code, possibly make it easier to use. Even package it up into a single easy to use class.
Today I’m happy to say that I finally did that. I released BNHtmlPdfKit on GitHub just a little bit ago. BNHtmlPdfKit easily turns HTML data from an HTML string or URL into a PDF file on iOS.
One of the things that always bothered me about my previous solution was the generated PDF files looked absolutely horrible because they were rendered at 72 dpi. I also knew that somehow there must have been a way to get the PDF file to generate using the UIPrintFormatter.
Turns out the solution was a tiny hack. Create a custom UIPrintPageRenderer and override paperRect
and printableRect
. This will cause the UIPrintFormatter to return a pageCount
as well as render the document.
Check out the Readme and feel free to fork the project!
In use by: