exportastiff.java
来自「Java生成PDF Java生成PDF Java生成PDF」· Java 代码 · 共 86 行
JAVA
86 行
// $Id: ExportAsTIFF.java,v 1.12 2007/11/13 04:28:15 mike Exp $package org.faceless.pdf2.viewer2.feature;import org.faceless.pdf2.viewer2.*;import org.faceless.pdf2.*;import javax.swing.*;import java.awt.image.*;import java.util.*;import java.util.Timer;import java.io.*;/** * Create a button and menu item to present a dialog to save the PDF as a TIFF image. * The name of this feature is "ExportAsTIFF". * <p><i>This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.</i></p> * @since 2.8 */public class ExportAsTIFF extends ViewerWidget{ public ExportAsTIFF() { super("ExportAsTIFF"); setButton("Document", "resources/icons/picture_save.png", "tt.ExportAsTIFF"); setMenu("File\tExport"); } public void action(final ViewerEvent event) { LinkedHashMap map = new LinkedHashMap(); final JTextField dpibox = new JTextField("72"); dpibox.setColumns(3); JFileChooser chooser = new JFileChooser(); chooser.setDialogType(JFileChooser.SAVE_DIALOG); map.put("File", chooser); map.put("export.DPI", dpibox); map.put("export.ColorModel", new JComboBox(new String[] { SuperJOptionPane.getLocalizedString("export.RGB"), SuperJOptionPane.getLocalizedString("export.Gray"), SuperJOptionPane.getLocalizedString("export.BW") })); Map out = (new SuperJOptionPane(map) { public String validate(Map vals) { try { int dpi = Integer.parseInt((String)vals.get("DPI")); if (dpi<1 || dpi>600) throw new Exception(); return null; } catch (Exception e) { return SuperJOptionPane.getLocalizedString("InvalidWhy", "DPI must be between 1 and 600"); } } }).getValues(event.getDocumentPanel(), "Export"); if (out!=null) { final int dpi = Integer.parseInt((String)out.get("DPI")); String name = (String)out.get("export.ColorModel"); final ColorModel cm; if (name.equals(SuperJOptionPane.getLocalizedString("export.RGB"))) { cm = PDFParser.RGB; } else if (name.equals(SuperJOptionPane.getLocalizedString("export.Gray"))) { cm = PDFParser.GRAYSCALE; } else { cm = PDFParser.BLACKANDWHITE; } final File file = (File)out.get("File"); final ProgressMonitor monitor = new ProgressMonitor(event.getViewer(), SuperJOptionPane.getLocalizedString("SavingFile", file.toString()), null, 0, 100); monitor.setMillisToDecideToPopup(10); monitor.setMillisToPopup(10); final PDFParser parser = new PDFParser(event.getPDF()); final Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { monitor.setProgress((int)(parser.getWriteAsTIFFProgress()*100)); } }, 100, 100); new Thread () { public void run() { try { OutputStream out = new FileOutputStream(file); parser.writeAsTIFF(out, dpi, cm); out.close(); timer.cancel(); monitor.close(); } catch (Exception e) { SuperJOptionPane.displayThrowable(SuperJOptionPane.getLocalizedString("Error"), e, event.getViewer()); } } }.start(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?