5.1. JSPプログラムの作成(JavaEE開発モデル)¶
JavaEE開発モデルとして、JSPのプログラムを作成します。
5.1.1. 準備¶
本チュートリアルでは、 Microsoft Word で作成したファイルを変換対象とします。
「 sample.docx 」のファイル名で作成し、 intra-mart Accel Platform サーバの< C:/temp >ディレクトリに配置してください。
5.1.2. JSPファイルの作成¶
テキストエディタを使用してJSPファイルを作成します。
Resin の場合、< %RESIN_HOME%/webapps/warファイルと同名のディレクトリ/ >の配下に「 convert.jsp 」の名前でファイルを作成し、次のソースを実装します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | <%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="yss.autoconverterex.soap.*" %>
<%@ page import="yss.autoconverterex.soap.com.exception.AutoExException" %>
<%@ taglib prefix="imui" uri="http://www.intra-mart.co.jp/taglib/imui" %>
<%
String src = "C:/temp/sample.docx";
String pdf = "C:/temp/out.pdf";
String outpdf = "";
String message = "Success !!";
AutoExRemote ex ;
int sts ;
String docinfname ;
int timeoutsec ;
/* インスタンスを作成 */
ex = new AutoExRemote();
/*****************************************************************************
文書情報、セキュリティ、スタンプの設定
*****************************************************************************/
if( false ) {
if( false ) {
/* 設定済みの文書情報及びセキュリティ設定の名前 */
docinfname = "docinf-name";
}
if( docinfname == null ) {
/* 文書情報を設定 */
ex.setDocInf(
"タイトル",
"サブタイトル",
"作成者",
"アプリケーション",
"キーワード");
}
else {
/* 文書情報を名前で指定して設定 */
ex.setDocInfByName(docinfname);
}
if( docinfname == null ) {
if( false ) {
/* 40ビットセキュリティの指定 */
ex.setSecurity40("open", "security",
true, true, true, true);
}
else {
/* 128ビットセキュリティの指定 */
ex.setSecurity128("open", "security",
AutoExRemote.SEC128PRINT_DISABLE,
AutoExRemote.SEC128ACC_DISABLE,
AutoExRemote.SEC128COPY_DISABLE,
AutoExRemote.SEC128DOCCHANGE_DISABLE);
}
}
else {
/* 文書情報を名前で指定して設定 */
ex.setDocInfByName(docinfname);
}
if( docinfname != null ) {
/* 文書情報及びセキュリティを名前で指定して設定 */
ex.setDocInfAndSecurity(docinfname);
}
if( false ) {
/* スタンプ(名前)の指定 */
ex.addStamp("stamp1");
}
/* Web用に最適化の有無 */
ex.setFastWebView(true);
}
/* プリンタ名の指定 */
ex.setPrinter("YSS PDF Converter XP");
/*****************************************************
変換前の別のタスクの処理に対するタイムアウト(秒)の設定
*****************************************************/
timeoutsec = 60 * 60;
timeoutsec = AutoExRemote.TIMEOUT_INFINITE;
ex.setBeforeTimeoutSec(timeoutsec);
/*****************************************************
変換時間に対するタイムアウト(秒)の設定
*****************************************************/
timeoutsec = 60 * 60;
timeoutsec = AutoExRemote.TIMEOUT_INFINITE;
ex.setTimeoutSec(timeoutsec);
/*****************************************************
ファイル送信から受信までのタイムアウト(ミリ秒)の設定
*****************************************************/
timeoutsec = 60 * 60 * 1000;
timeoutsec = AutoExRemote.TIMEOUT_INFINITE;
ex.setTransTimeoutSec(timeoutsec);
try {
/* PDF変換 */
outpdf = ex.convert(src, pdf);
}
catch(Exception e) {
e.printStackTrace();
message = e.getMessage();
}
%>
<imui:head>
<title>IM-PDFAutoConverter-チュートリアル-JavaEE開発モデル-convert</title>
</imui:head>
<div class="imui-title">
<h1>IM-PDFAutoConverter チュートリアル JavaEE開発モデル convert</h1>
</div>
<div class="imui-form-container">
<div class="imui-chapter-title"><h2>実行結果</h2></div>
<table class="imui-table">
<tbody>
<tr>
<th class="wd-20">出力PDFファイル</th>
<td><%= outpdf %></td>
</tr>
<tr>
<th class="wd-225px">メッセージ</th>
<td><%= message %></td>
</tr>
</tbody>
</table>
</div>
|
注意
文字コードを UTF-8 にして保存してください。
注意
PDF変換処理であるAutoExRemote.convert(inFilePath, outFilePath)は、エラー発生時にExceptionをスローします。
エラー情報を取得するために、上記メソッドをtry-catch文で括ってください。
5.1.3. プログラムの登録¶
作成したJSPファイルを環境に適用するため、 Web Application Server を再起動してください。
再起動後、プログラムをメニューに設定します。
5.1.3.1. メニュー設定¶
テナント管理者でログインし、次のメニューを設定します。
[テナント管理]-[メニュー]画面を開きます。
フォルダを作成します。
URLに、convert.jsp を設定し、メニューを追加します。
メニュー設定は完了です。
5.1.4. プログラムの実行と確認¶
メニューで「 convert 」を選択することにより、作成したプログラムが実行されます。
実行後は intra-mart Accel Platform サーバの< C:/temp >ディレクトリに、変換されたPDFファイル「 out.pdf 」が出力されます。
PDFビューア( Adobe Acrobat Reader など)でファイルが正しく表示されることを確認し、このチュートリアルは完了です。