This section shows how to display and print a spreadsheet. Everything is done in Java and does not require any external application.
Developpers having used OpenOffice/LibreOffice and UNO to do this job will be happy to find here a faster and easier approach to display and print document.
There a 2 ways to print a spreadsheet. You can allow the user to print directly from the built-in viewer or manage the entire process programmaticaly.
// Load the spreadsheet.
|
A print button appears in the toolbar:
The DefaultDocumentPrinter is very basic on only try to fit the document on the printed page.
You can easily change this behaviour by implementing the DocumentPrinter interface.
// Load the spreadsheet.
|
The DefaultDocumentPrinter will open a print dialog. If you preffer to print without user interaction, just look a the ODTPrinter class and remove the call to printJob.printDialog().
If you are familiar with the Java printing API, you will be able to create quickly your own DocumentPrinter.