3 * $Date: 2009-06-30 18:58:33 -0500 (Tue, 30 Jun 2009) $
\r
6 * Copyright (C) 2002-2005 The Jmol Development Team
\r
8 * Contact: jmol-developers@lists.sf.net
\r
10 * This library is free software; you can redistribute it and/or
\r
11 * modify it under the terms of the GNU Lesser General Public
\r
12 * License as published by the Free Software Foundation; either
\r
13 * version 2.1 of the License, or (at your option) any later version.
\r
15 * This library is distributed in the hope that it will be useful,
\r
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
\r
18 * Lesser General Public License for more details.
\r
20 * You should have received a copy of the GNU Lesser General Public
\r
21 * License along with this library; if not, write to the Free Software
\r
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 import java.util.Hashtable;
\r
27 import java.util.Map;
\r
29 import javajs.export.PDFCreator;
\r
32 * A relatively primitive PDF generator that just makes a document with an image
\r
36 public class PdfEncoder extends ImageEncoder {
\r
38 private boolean isLandscape;
\r
39 private PDFCreator pdf;
\r
40 private String comment;
\r
42 public PdfEncoder() {
\r
43 // for Class.forName
\r
47 protected void setParams(Map<String, Object> params) {
\r
48 isLandscape = (quality > 1);
\r
49 comment = "Jmol " + (String) params.get("comment");
\r
53 protected void generate() throws Exception {
\r
54 pdf = new PDFCreator();
\r
55 int pageWidth = 8 * 72;
\r
56 int pageHeight = 11 * 72;
\r
57 pdf.setOutputStream(out);
\r
58 pdf.newDocument(pageWidth, pageHeight, isLandscape); // A4 or Letter
\r
59 addMyImage(pageWidth, pageHeight);
\r
60 Map<String, String> ht = new Hashtable<String, String>();
\r
61 if (comment != null)
\r
62 ht.put("Producer", comment);
\r
63 ht.put("Author", "JMol");
\r
64 ht.put("CreationDate", date);
\r
66 pdf.closeDocument();
\r
71 * centered on the page
\r
76 private void addMyImage(int pageWidth, int pageHeight) {
\r
77 pdf.addImageResource("img1", width, height, pixels, true);
\r
78 int w = (isLandscape ? pageHeight : pageWidth);
\r
79 int h = (isLandscape ? pageWidth : pageHeight);
\r
83 ih = (int) (ih * 0.9 * w / iw);
\r
84 iw = (int) (w * 0.9);
\r
87 iw = (int) (iw * 0.9 * h / ih);
\r
88 ih = (int) (h * 0.9);
\r
102 pdf.drawImage("img1", x, y, x1, y1, 0, 0, width, height);
\r