- pdfkit is a good library for generating pdf output and it will be testet first
- pdfmake is a wrapper around pdfkit which make it simpler to define pdf reports and it also provides the opportunity to use it in the client
Both solutions will be testet. The documentation so far lacks the printing of footers and of page-numbers, but I'm sure, there will be solutions.
The first usecase is creating a pdf file for the diary data of one day. To support that, a print icon will be supplied for the diary entry.
A first test with pdfmake from the browser with download of the generated pdf-file was very promising.
Some background is given in http://gonehybrid.com/how-to-create-and-display-a-pdf-file-in-your-ionic-app/
PDF.js is a pdf viewer for usage in the browser and in an app.
The printing of the pdf documents seems to be a little bit more complicated. There are various approaches working with cordova:
- the approach sarahgoldman/cordova-print-pdf-plugin prints pdf after conversion to base64 and communicates with AirPrint for iOS and Android Printing APIs
- the approach katzer/cordova-plugin-printer can print html-content from iOS, Android and Windows Universal apps
- create basic docDefinition als JSON
- add more data to the docDefinition with JavaScript-Statements
- create the pdf-File
You have to get accustomed to using the styles, but once you get it, it's very easy.
A challenge is using richt text from CKEditor, there are some html-tags in the text, so a conversion is necessary.
- <br> to /n
- <b> and </b> to a new paragraph with style strong
- list-header and list-elements have to be converted accordingly
On github there is an approach using the DOM for the conversion - seems to be promising. In https://github.com/bpampuch/pdfmake/issues/205 there is a discussion to this challenge and http://jsfiddle.net/mychn9bo/75/ shows a good approach.
As the diary app has various data like text, richt text and tables in the MongoDB and IndexedDB documents, it seems to be good to use a modular approach that generates the paragraphs for the pdf from the data-elements.
No comments:
Post a Comment