1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.wiki.ui.editor;
14 import java.io.FileNotFoundException;
15 import java.io.FileOutputStream;
17 import org.eclipse.jface.action.Action;
18 import org.eclipse.swt.SWT;
19 import org.eclipse.swt.widgets.Display;
20 import org.eclipse.swt.widgets.FileDialog;
21 import org.eclipse.swt.widgets.Shell;
23 import com.lowagie.text.Document;
24 import com.lowagie.text.DocumentException;
25 import com.lowagie.text.PageSize;
26 import com.lowagie.text.pdf.PdfWriter;
28 public class WikiExportPDFAction extends Action {
30 final IExportable exportable;
32 public WikiExportPDFAction(IExportable exportable) {
33 this.exportable = exportable;
38 Shell shell = Display.getCurrent().getActiveShell();
40 FileDialog fd = new FileDialog(shell, SWT.SAVE);
41 fd.setText("Save PDF");
42 fd.setFilterPath("C:/");
43 String[] filterExt = { "*.pdf", "*.*" };
44 fd.setFilterExtensions(filterExt);
45 String filename = fd.open();
52 protected void exportPDF(String filename) {
53 Document document = new Document(PageSize.A4,36,36,36,36);
55 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
57 exportable.export(document, writer);
58 } catch (FileNotFoundException e) {
59 // TODO Auto-generated catch block
61 } catch (DocumentException e) {
62 // TODO Auto-generated catch block