'Build complex PDF in kotlin [closed]
I want to create "complex" (footer, header, cells and pictures) pdf for my android application (kotlin). I've seen some people already asked for something similar (PrintedPdfDocument, PdfDocument, iText, XML to Webview to PDF) but it look more like a workaround than a best practice.
Do someone know how to do something similar to the picture below
Solution 1:[1]
You forgot Apache pdfbox https://pdfbox.apache.org/ (with the Android build https://github.com/TomRoush/PdfBox-Android)
They all have pro's and con's
e.g.
iText will probably need to pay for a commercial license
PdfBox, a lot of useful other libraries that use this don't have Android ports
.. the list goes on.
You just have to evaluate what is important to you.
I had a fairly complex pdf to generate that had tables and splitting tables across pages, headers, footers and one image.
All these types of things were easy with Android Views/Layouts.
So in the end I went PdfDocument (though it has some annoying bugs in it pre Android 6)
Because I could generate a view/layout easily how I wanted a single page and then layout/measure/draw it to a pdf page.
In the end because pdf's have a low resolution of 1/72 of an inch to match standard paper sizes and because I also wanted PNG files as an output option. I went with drawing layouts/view to Bitmaps for a single page at higher resolutions and then just put Bitmap in to the PDF with a scale to fit it to the page.
The downside of just putting a Bitmap in to a PDF is that text is not selectable, but for me this was actually a useful security feature.
Using layout/views is handy if you want a similar display on the screen as you want in the PDF.
I did have to use the "Bonus Feature" of a TableLayout type library I had created for another reason to get better control of sizes of columns than the standard Android TableLayout (It allowed me to align a header table with a content Table and align Tables across pages)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Andrew |