--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
+ * in Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ * VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.wiki.ui.editor;\r
+\r
+import java.io.FileNotFoundException;\r
+import java.io.FileOutputStream;\r
+\r
+import org.eclipse.jface.action.Action;\r
+import org.eclipse.swt.SWT;\r
+import org.eclipse.swt.widgets.Display;\r
+import org.eclipse.swt.widgets.FileDialog;\r
+import org.eclipse.swt.widgets.Shell;\r
+\r
+import com.lowagie.text.Document;\r
+import com.lowagie.text.DocumentException;\r
+import com.lowagie.text.PageSize;\r
+import com.lowagie.text.pdf.PdfWriter;\r
+\r
+public class WikiExportPDFAction extends Action {\r
+\r
+ final IExportable exportable;\r
+ \r
+ public WikiExportPDFAction(IExportable exportable) {\r
+ this.exportable = exportable;\r
+ }\r
+ \r
+ public void run() {\r
+ \r
+ Shell shell = Display.getCurrent().getActiveShell();\r
+\r
+ FileDialog fd = new FileDialog(shell, SWT.SAVE);\r
+ fd.setText("Save PDF");\r
+ fd.setFilterPath("C:/");\r
+ String[] filterExt = { "*.pdf", "*.*" };\r
+ fd.setFilterExtensions(filterExt);\r
+ String filename = fd.open();\r
+ if (filename == null)\r
+ return;\r
+ exportPDF(filename);\r
+ \r
+ }\r
+ \r
+ protected void exportPDF(String filename) { \r
+ Document document = new Document(PageSize.A4,36,36,36,36);\r
+ try {\r
+ PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));\r
+ document.open();\r
+ exportable.export(document, writer);\r
+ } catch (FileNotFoundException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } catch (DocumentException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ } finally {\r
+ document.close();\r
+ }\r
+ }\r
+}\r