7

最後にいくつかのドキュメントを印刷するソフトウェアをJavaで構築する必要があります。異なるドキュメントは、プリンタの異なるトレイに送られる必要があります。開発中はお客様と同じプリンターを利用できないため、プリンターを模倣する小さなソフトウェアを探しています。たとえば、使用可能なトレイの数など、そのモックを構成できるはずです。

MacやWindows用のそのようなツールを知っている人はいますか?

4

3 に答える 3

4

顧客の「実際の」プリンター用に 1 回、「仮想」プリンター用に 1 回実装する抽象レイヤーを作成します。顧客バージョンの統合テストを作成し、それらのテストを顧客の環境で実行します。抽象化レイヤーに対するコード。

于 2012-12-20T08:43:23.450 に答える
4

特別なソフトウェアを使用しなくても、Windows 上で自分でダミー プリンターを作成できます。

Windows 7 の場合:

  1. コントロールパネル
  2. デバイスとプリンター
  3. [右クリック] プリンターの追加
  4. ローカル プリンターを追加する
  5. 既存のポートを使用します (既に存在すると仮定し、存在しない場合は新しいポートを作成します)
  6. File: (ファイルに出力する)、NUL: (どこにも出力しない) または CON: (コンソールに出力する)
  7. プリンターのリストからエミュレートするプリンターを選択します。

デフォルトのプリンターとして設定すると、Java コードから簡単に使用できるはずです。

于 2012-12-20T08:43:32.373 に答える
0

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);
}
}
于 2014-11-27T16:48:54.800 に答える