Dynamic PDF generation and Word/DOCX to PDF conversion


We want to use PDFNet mobile (e.g. Xamarin Android) to dynamically generate lengthy PDF documents.
We need the ability to include and exclude pages and large chunks of text depending on certain conditions. What would be the best way to accomplish that with your tool and retain consistent layout and page numbering?


Regarding PDF Generation, PDFNet supports multiple options (https://groups.google.com/d/msg/pdfnet-sdk/lhM9u-FwSZ0/4onXcbvwiLgJ).
Since you need to generate very dynamic and lengthy reports, I would like to suggest using DOCX to PDF conversion which is available as an option in PDFNet SDK (see https://blog.pdftron.com/2015/09/08/convert-word-to-pdf/)

The idea is that you generate DOCX (e.g. either on-the-fly or from an existing DOCX template) then pass DOCX in the call to pdftron.PDF.Convert.WordToPDF(pdfdoc, docx, null);

To be more concrete I attached is a small sample showing how to dynamically generate PDF via DOCX.

To run the sample, simply download PDFNet for .NET and extract the attached WordToPDFTest in PDFNetDotNet/Samples folder (replacing the existing WordToPDFTest sample).
Run the project and you will find a number of generated PDFs under PDFNetDotNet\Samples\TestFiles\Output

The interesting functionality is in Samples/WordToPDFTest/InvoiceGenerator.cs. The sample uses a simple DOCX generator (http://docx.codeplex.com), but you could use any other method to generate DOCX (e.g.
Microsoft OpenXML library is more feature rich and also available on Xamarin & Android https://github.com/wotzisname/open-xml-sdk-xamarin, https://github.com/OfficeDev/Open-XML-SDK, Docs: https://github.com/OfficeDev/office-content/tree/master/en-us/OpenXMLCon)

There are many other ways to generate DOCX. Since DOCX is just XML (WordML) you could even generate it manually via String.