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