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