3 * $Date: 2009-06-30 18:58:33 -0500 (Tue, 30 Jun 2009) $
6 * Some portions of this file have been modified by Robert Hanson hansonr.at.stolaf.edu 2012-2017
7 * for use in SwingJS via transpilation into JavaScript using Java2Script.
9 * Copyright (C) 2002-2005 The Jmol Development Team
11 * Contact: jmol-developers@lists.sf.net
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29 import java.util.Hashtable;
32 import javajs.export.PDFCreator;
35 * A relatively primitive PDF generator that just makes a document with an image
39 public class PdfEncoder extends ImageEncoder {
41 private boolean isLandscape;
42 private PDFCreator pdf;
43 private String comment;
50 protected void setParams(Map<String, Object> params) {
51 isLandscape = (quality > 1);
52 comment = "Jmol " + (String) params.get("comment");
56 protected void generate() throws Exception {
57 pdf = new PDFCreator();
58 int pageWidth = 8 * 72;
59 int pageHeight = 11 * 72;
60 pdf.setOutputStream(out);
61 pdf.newDocument(pageWidth, pageHeight, isLandscape); // A4 or Letter
62 addMyImage(pageWidth, pageHeight);
63 Map<String, String> ht = new Hashtable<String, String>();
65 ht.put("Producer", comment);
66 ht.put("Author", "JMol");
67 ht.put("CreationDate", date);
74 * centered on the page
79 private void addMyImage(int pageWidth, int pageHeight) {
80 pdf.addImageResource("img1", width, height, pixels, true);
81 int w = (isLandscape ? pageHeight : pageWidth);
82 int h = (isLandscape ? pageWidth : pageHeight);
86 ih = (int) (ih * 0.9 * w / iw);
90 iw = (int) (iw * 0.9 * h / ih);
105 pdf.drawImage("img1", x, y, x1, y1, 0, 0, width, height);