Export to PDF

PDF Exporter

In addition to the xlsx format, you can also export a book model into a PDF file with io.keikai.api.Exporter.

Required Module

Before exporting, you need to include keikai-pdf module to make PdfExporter available for your application. (See Modules)

Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
public class ExportPdfComposer extends SelectorComposer<Component> {

    @Wire
    private Spreadsheet ss;

    Exporter exporter = Exporters.getExporter("pdf");
    
    
    @Listen("onClick = #exportPdf")
    public void doExport() throws IOException{
        Book book = ss.getBook();
        
        File file = File.createTempFile(Long.toString(System.currentTimeMillis()),"temp");
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(file);
            exporter.export(book, file);
        }finally{
            if(fos!=null){
                fos.close();
            }
        }
        Filedownload.save(new AMedia(book.getBookName()+".pdf", "pdf", "application/pdf", file, true));
    }

    ...
}

Line 6: Get an Exporter instance for PDF format first.

Supported Excel Printing Setup

Spreadsheet exports its book model to a PDF file according to the page print setup you specify in Excel.

For example, you can add a header and footer, and it would look like:

You can also scale a sheet to fit into one page with row and column heading:

Supported Page Setup

The page setup properties of Excel which are supported by Spreadsheet are listed below:

Page

  • Orientation
    • Portrait, Landscape
  • Scaling
    • Adjust to % normal size
    • Fit to pages wide by tall
  • Page size
  • First page number

Margins

  • Top
  • Header
  • Right
  • Footer
  • Bottom
  • Left

Center on Page

  • Horizontally
  • Vertically

Breaks

Header/Footer

  • Custom Header…
  • Custom Footer…
  • Different odd and even pages
  • Different first page

Sheet

  • Print area
  • Print titles
    • Rows to repeat at top
    • Columns to repeat at left
  • Print
    • Gridlines
    • Row and column headings
  • Page order
    • Down, then over
    • Over, then down
Get code at GitHub

Comments