I want to create a PDF invoice inside my iOS App (either in Objective-C or Swift).
My main problem is that the invoice might have several pages, which is very difficult to realize with the existing APIs from Apple (CoreGraphics, Quartz 2D, etc).
By now, I already have a barely working solution:
- I created a HTML template which is the basic structure for the invoice
- The template is filled with data using GRMustache
- I load the generated HTML file into a
UIWebView
and save it as PDF (I used NDHTMLtoPDF to do this)
So far, so good.
The problem with this solution is that page breaks don't work properly.
There are some tables and images and the page break often cut's off tables or images.
I have tried to use the page-break-inside: avoid;
css property for the images and the tables but UIWebView
seems to ignore them completely...
My question is:
- Do you know how to fix the page break problem?
- Can you recommend another solution to create PDFs on iOS?
- Should I design the invoice in Storyboard and generate a PDF from the
UIView
? What about the page breaks here?
I would prefer to have a template (e.g. HTML), fill it with data and save it as PDF, rather than doing everything in code.