Dynamic PDF generation and Word/DOCX to PDF conversion

290 views
Skip to first unread message

Support

unread,
Nov 16, 2016, 7:14:20 PM11/16/16
to PDFTron PDFNet SDK
Q: 
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?

-------

A:

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. 

There are many other ways to generate DOCX. Since DOCX is just XML (WordML) you could even generate it manually via String.
WordToPDFTest.zip
Reply all
Reply to author
Forward
0 new messages