IOS create PDF invoice

I want to create a PDF invoice in my iOS app (either Objective-C or Swift).
My main problem is that the invoice can have multiple pages, which is very difficult to implement using existing APIs from Apple (CoreGraphics, Quartz 2D, etc.).

By now, I already have a barely working solution:

  • I created an HTML template which is the basic structure for an invoice
  • Template is filled with data using GRMustache
  • I load the generated HTML file into UIWebView

    and save it as PDF (I used NDHTMLtoPDF for this)

So far so good.

The problem with this solution is page breaks are not working as expected. There are multiple tables and images, and page breaks often interrupt tables or images.
I tried using the page-break-inside: avoid;

css property for images and tables but UIWebView

seems to ignore them completely ...

My question is:

  • Do you know how to fix a page break issue?
  • Can you recommend another solution for creating PDF files in iOS?
  • Do I have to bill Storyboard and generate PDF from UIView

    ? How about a page break here?

I would rather have a template (like HTML), fill it with data, and save it as PDF, rather than do everything in code.

+3


source to share


1 answer


I actually wrote a PDF reporting component with supposedly similar requirements:

  • templating is done via HTML / CSS
  • Static header / footer on every page

You can achieve this with the UIPrintPageRenderer and UIViewPrintFormatter APIs, with the downside of probably rejecting your app in the app store overview since you are using Apple private APIs. Thus, this approach may only be viable in an academic setting or in the case of developing your own applications.



There are several tutorials on how to do this that I won't repeat, but these resources have been quite helpful to me:

0


source







All Articles