Dynamic PDF creation on Android

Q:

I have a requirement to draw a table with column data - mostly text.


Item # Description Number of Items Price Per Item Total


In this case the Description can be really long in the invoice. And it needs to wrap within the Description Column.

Also as I do not know how many line items and how many pages I am going to add, it supported the concept of listening to Page Events for me to know that when I write I can duplicate the Header (Billing Address) and Footer (Company Information) etc.,

As you can image, I don’t want to do the calculations of where I am in the page, do I have enough pixiels left in the page, do I need to split a line item between two pages etc.,

So I was wondering if there are higher-level API on Android to support functionality like that?

I found the following possibly related code https://groups.google.com/d/topic/pdfnet-sdk/bSYgR77JiAw/discussion, but this seems to be .NET related.


A:

For document creation options via PDFNet please see:

https://groups.google.com/d/topic/pdfnet-sdk/lhM9u-FwSZ0/discussion

The simplest way to create dynamic PDF is using Xaml2Pdf (http://www.pdftron.com/pdfnet/samplecode.html#Xaml2Pdf) or Html2Pdf (http://www.pdftron.com/pdfnet/samplecode.html#Html2Pdf) approach.

Unfortunately, at the moment, neither of these methods is available in mobile SDKs (except for the upcoming WinRT SDK). So the two options for dynamic PDF generation on Android are:

a) Use low-level ElementBuilder/Writer (as shown in the article you sent, https://groups.google.com/d/topic/pdfnet-sdk/bSYgR77JiAw). In this sample Table structure is WPF artifact, however you can replace it with your own or Android specific classes. The structure just contains a text data collection representing a table.

b) You can also send an XML request to your server where PDFNet could convert XML (or HTML) to PDF. In this case there are many conversion and PDF generation options (including FlowDocument to PDF, XAML to PDF, DOC/DOCX to PDF, HTML to PDF, etc.