Export to PDF

From Documentation


PDF Exporter

Available in ZK Spreadsheet EE only


In addition to the Excel format, you can also export a book model as a PDF file with Exporter

Example to export as a PDF

package org.zkoss.zss.essential;

import java.io.*;

import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.select.SelectorComposer;
import org.zkoss.zk.ui.select.annotation.*;
import org.zkoss.zss.api.*;
import org.zkoss.zss.api.model.Book;
import org.zkoss.zss.ui.Spreadsheet;
import org.zkoss.zul.*;

public class ExportPdfComposer extends SelectorComposer<Component> {

	@Wire
	private Spreadsheet ss;
	@Wire("combobox")
	private Combobox combobox;

	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));
	}

	//omit some code for brevity
}

Line 21: Get an Exporter instance for PDF format.

Load Excel Printing Setup

Since 3.6.0

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

ExcelPageSetup.png

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

PdfExporting-HeaderFooter.png


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

PdfExporting-FitOnePage.png

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

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