クライアント側でのレポートの印刷について

文書番号 : 39574     文書種別 : 技術情報     登録日 : 2016/09/30     最終更新日 : 2016/09/30
文書を印刷する
対象製品
Elixir Report 8.7J
詳細
サーバーサイドで生成した帳票を、クライアントサイドのコンピュータに画面表示させずにダイレクトで印刷させることができます。
この印刷は、クライアントPC上でアプレットやスタンドアロンJavaアプリケーションを実行し、Java Print Service(JPS)を利用して、指定したクライアント側のプリンタに出力する方法で行います。

次のサンプルはアプレット用のクラスと呼び出しHTMLのサンプルです。
※アプレットの実行にはセキュリティの考慮が必要です。

■サンプルコード
// アプレット用クラスのサンプルコード
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Properties;

import javax.print.PrintService;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;

// レポートサーバーAPIクラスのインポート
import com.elixirtech.ers2.client.ERSClient;
import com.elixirtech.glint.print.GlintStreamPrinter;
import com.elixirtech.glint.print.PrinterUtil;
import com.elixirtech.report2.runtime.IJobInfo;

public class AppletDirectPrintDemo extends java.applet.Applet {
  
  public void init(){
      // レポートサーバー
      String m_Host = "HOSTNAME";
      int m_Port = 7001;
      String m_User = "User1";
      String m_Password = "password";

      // レポートサーバー接続管理オブジェクトの作成
      ERSClient client = new ERSClient(m_Host, m_Port, m_User, m_Password);
      ByteArrayOutputStream bout = new ByteArrayOutputStream();

      // レポートパラメータ用プロパティオブジェクト
      Properties prop = new Properties();
      //prop.put( "MyParam" , "valuename" );

      try{
        // Glint形式のレポート生成リクエストを発行
        IJobInfo job = client.renderReport(
          "/samples/demo/nouhinsyo/nouhinsyo.rml", "application/x-glint", bout , prop);

        GlintStreamPrinter gsp = new GlintStreamPrinter();
        PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();

        // プリンタ名一覧の取得(クライアントのOSに接続されたプリンタ名の確認)
        // String[] printer = PrinterUtil.getPrinters();
        // 取得したプリンタ名をコンソールに出力
        // for(int i=0; i<printer.length; i++){
        //  System.out.println("プリンタ"+ i + ": " + printer[i]);
        // }

        // プリンタ名の指定(クライアントのOSに接続されたプリンタ)
        PrintService ps = PrinterUtil.getSelectedPrintService("Microsoft XPS Document Writer");
        gsp.printNonInteractive(ps, new ByteArrayInputStream(bout.toByteArray()), aset, null);
    }catch (Exception e){
      e.printStackTrace();
    }
  }
}

// アプレット呼び出しHTMLのサンプルコード
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-31j">
    <title>アプレットで印刷</title>
  </head>
  <body>
    ※アプレットで印刷(クライアントのOSに接続されたプリンタ出力)
    <applet code="AppletDirectPrintDemo.class"
      archive="glint.jar, reportserver-api.jar, log4j.jar"
      width="300" height="250">
    </applet>
  </body>
</html>