-1

I have an app that generates report from database and displays it in tablelayout , the problem is I don't know how to print a hardcopy of the table content. Preferably print to PDF ... Thanks (Java not Kotlin)

1 Answers1

0

One cheat way is to draw the layout to a separate canvas that is as big as needs to be when laid out with wrap content and no restrictions on size.

See the answer https://stackoverflow.com/a/60582865/2373819 on how to do this with a tableLayout.

Then print the bitmap that backs the canvas as a picture by


// Draw to bitmap stuff in other answer ... then

PrintHelper photoPrinter = new PrintHelper(this);
        photoPrinter.setScaleMode(PrintHelper.SCALE_MODE_FIT);
        photoPrinter.setOrientation(PrintHelper.ORIENTATION_LANDSCAPE);
        photoPrinter.printBitmap("Print Jobname", bitmap);

Then you can select a real printer or the inbuilt "print to PDF" in the GUI

Note that this can be very memory hungry for large tables and it will only print one page wide and however many pages long.

Andrew
  • 8,198
  • 2
  • 15
  • 35