I have an android linear layout which I want to convert as a PDF. Many a times, this PDF would span multiple pages. While I am able to convert the content into a single page PDF, have some difficulty in breaking the PDF into a multi-page one. I have given the relevant code block below, hard coded some numbers for simplicity sake. Here, PdfDocument.PageInfo.Builder takes 3 arguments - width, height and page number (earlier, it used to accept new Rect(0,0,800,100) which is not working any longer in API 23). Now, when I iterate through the for loop, I am not sure how I can get different content for a multi-page PDF. The current piece of code given below generates same content for every page, since it is based on width and height and not based on co-ordinates.
PdfDocument.PageInfo pageInfo;
int noOfPages = (int)Math.floor(content.getHeight()/1000)+1;
for (int i=1;i<=noOfPages;i++) {
pageInfo = new PdfDocument.PageInfo.Builder
(800,1000,i).create();
PdfDocument.Page page = document.startPage(pageInfo);
content.draw(page.getCanvas());
document.finishPage(page);
}
Its been more than 2 years, since i last worked on PDFDocument stuff, so sorry i don't have exact answer for your question, but i will share my little knowledge on it, hope it will help you.
Sample
Look at the code which i wrote 2Years back, which may help you - https://gist.github.com/apvasanth03/ed903535aed12c93e30b102d9596c399
Note
It will be difficult, how to break your view into different page's if it contains a TextView with several lines. I don't have answer for it.
Kindly, share if you find any solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With