最後にいくつかのドキュメントを印刷するソフトウェアをJavaで構築する必要があります。異なるドキュメントは、プリンタの異なるトレイに送られる必要があります。開発中はお客様と同じプリンターを利用できないため、プリンターを模倣する小さなソフトウェアを探しています。たとえば、使用可能なトレイの数など、そのモックを構成できるはずです。
MacやWindows用のそのようなツールを知っている人はいますか?
最後にいくつかのドキュメントを印刷するソフトウェアをJavaで構築する必要があります。異なるドキュメントは、プリンタの異なるトレイに送られる必要があります。開発中はお客様と同じプリンターを利用できないため、プリンターを模倣する小さなソフトウェアを探しています。たとえば、使用可能なトレイの数など、そのモックを構成できるはずです。
MacやWindows用のそのようなツールを知っている人はいますか?
顧客の「実際の」プリンター用に 1 回、「仮想」プリンター用に 1 回実装する抽象レイヤーを作成します。顧客バージョンの統合テストを作成し、それらのテストを顧客の環境で実行します。抽象化レイヤーに対するコード。
特別なソフトウェアを使用しなくても、Windows 上で自分でダミー プリンターを作成できます。
Windows 7 の場合:
デフォルトのプリンターとして設定すると、Java コードから簡単に使用できるはずです。
Java アプリケーションの仮想プリンターとして機能する PDF 印刷をインストールできます。基本的に、無料で入手できる PDF プリンターをインストールし、Java アプリケーションでその印刷サービスを検出して、そのサービスにドキュメントを印刷します。プリンターを持っていなかったときに同じ状況が発生したことを覚えています。以下のコードを使用して、アプリケーションと仮想プリンターをインターフェイスさせました。
public class HelloWorldPrinter implements Printable, ActionListener {
public int print(Graphics g, PageFormat pf, int page) throws
PrinterException {
if (page > 0) { /* We have only one page, and 'page' is zero-based */
return NO_SUCH_PAGE;
}
/* User (0,0) is typically outside the imageable area, so we must
* translate by the X and Y values in the PageFormat to avoid clipping
*/
Graphics2D g2d = (Graphics2D)g;
g2d.translate(pf.getImageableX(), pf.getImageableY());
/* Now we perform our rendering */
g.drawString("Hello world!", 100, 100);
/* tell the caller that this page is part of the printed document */
return PAGE_EXISTS;
}
public void actionPerformed(ActionEvent e) {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
PrintService[] printServices = PrinterJob.lookupPrintServices();
try {
job.setPrintService(printServices[0]);
job.print();
} catch (PrinterException ex) {
Logger.getLogger(HelloWorldPrinter.class.getName()).log(Level.SEVERE, null, ex);
}
}
public static void main(String args[]) {
UIManager.put("swing.boldMetal", Boolean.FALSE);
JFrame f = new JFrame("Hello World Printer");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {System.exit(0);}
});
JButton printButton = new JButton("Print Hello World");
printButton.addActionListener(new HelloWorldPrinter());
f.add("Center", printButton);
f.pack();
f.setVisible(true);
}
}