IM-PDFCoordinator for Accel Platform プログラミングガイド 第12版 2023-10-01

5.1. JSPプログラムの作成( JavaEE開発モデル )

JavaEE開発モデル として、JSPのプログラムを作成します。

5.1.1. 準備

本チュートリアルでは、 PDFファイルを処理対象とし、セキュリティ機能(Security) (利用するAPIは jp.co.iothe.pdfprotection パッケージ)のプログラムを作成します。

「 sample.pdf 」のファイル名でPDFファイルを用意し、 intra-mart Accel Platform サーバの< C:/temp >ディレクトリに配置してください。

5.1.2. JSPファイルの作成

テキストエディタを使用してJSPファイルを作成します。

Resin の場合、< %RESIN_HOME%/webapps/warファイルと同名のディレクトリ/ >の配下に「 protection.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
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ page import="java.util.Date" %>
<%@ page import="java.text.ParseException" %>
<%@ page import="java.text.SimpleDateFormat" %>

<%@ page import="jp.co.iothe.pdfprotection.PdfProtection" %>
<%@ page import="jp.co.iothe.pdfprotection.PdfProtectionException" %>
<%@ page import="jp.co.iothe.pdfprotection.PdfProtectionFactory" %>

<%@ taglib prefix="imui" uri="http://www.intra-mart.co.jp/taglib/imui" %>
<%
	String	src		= "C:/temp/sample.pdf";
	String	pdf		= "C:/temp/out.pdf";
	String	outpdf		= "";
	String	message		= "Success !!";

	PdfProtection		protection	;
	int			sts		;
	String			docinfname	;

	// セキュリティ強化APIのインスタンスを生成します
	// 設定ファイルに従ってリモートまたは直接使用のインスタンスを生成します
	protection = PdfProtectionFactory.createPdfProtection();

	// 文書情報を設定します
	// このメソッドを実行しなかった場合、文書情報はすべて空になります
	protection.setDocInfo(
			"タイトル",
			"サブタイトル",
			"作成者",
			"アプリケーション",
			"キーワード"
			);

	// 標準セキュリティを設定します
	// RC4-128ビットとAES128ビットのセキュリティはどちらか片方しか付与されません(最後に実行した方が有効)
	// このメソッドを実行しなかった場合、標準セキュリティは付与されません
	if( true ) {
		System.out.println("RC4-128ビットのセキュリティ");
		// RC4-128ビットのセキュリティを設定します
		protection.setSecurity128("open", "security",
			PdfProtection.SEC128PRINT_DISABLE,
			PdfProtection.SEC128ACC_DISABLE,
			PdfProtection.SEC128COPY_DISABLE,
			PdfProtection.SEC128DOCCHANGE_DISABLE);
	}
	else {
		System.out.println(" AES128ビットのセキュリティ");
		// AES128ビットのセキュリティを設定します
		protection.setSecurityAES128("open", "security",
			PdfProtection.SEC128PRINT_DISABLE,
			PdfProtection.SEC128ACC_DISABLE,
			PdfProtection.SEC128COPY_DISABLE,
			PdfProtection.SEC128DOCCHANGE_DISABLE);
	}

	// Webに最適化するかどうかを設定します
	protection.setFastWebView(true);

	// 上記で設定した情報を元にセキュリティを強化して新しいPDFを出力します
	int result;
	if (true) {
		// 編集元PDFにセキュリティパスワードが設定されていない場合
		result = protection.outputPdf(src, pdf);
	}
	else {
		// 編集元PDFにセキュリティパスワードが設定されている場合
		result = protection.outputPdf(src, "password", pdf);
	}

	// outputPdfで発生した例外を取得します
	if (result < 0) {
		PdfProtectionException exception = protection.getException();
		message = exception.getMessage();
	}
%>
<imui:head>
  <title>IM-PDFCoordinator-チュートリアル-JavaEE開発モデル-protection</title>
</imui:head>

<div class="imui-title">
  <h1>IM-PDFCoordinator チュートリアル JavaEE開発モデル protection</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><%= pdf %></td>
        </tr>
        <tr>
          <th>戻り値</th>
          <td><%= result %></td>
        </tr>
        <tr>
          <th>メッセージ</th>
          <td><%= message %></td>
        </tr>
      </tbody>
    </table>
</div>

注意

文字コードを UTF-8 にして保存してください。

コラム

標準セキュリティのRC4-128ビット、および、AES128ビットのセキュリティは、どちらか片方のみ付与されます。

セキュリティ設定処理を複数実行した場合、最後に実行したセキュリティ設定が有効になります。

コラム

URLのセキュリティはワイルドカード「*」が使用できます。このセキュリティを使用する場合、標準セキュリティで転載と文書変更を許可しないよう設定してください。

コラム

有効期限のセキュリティはfromとtoのどちらか片方だけ設定することもできます。このセキュリティを使用する場合、標準セキュリティで転載と文書変更を許可しないよう設定してください。setSecurityDateでは、年月日までしか指定できません。

5.1.3. プログラムの登録

作成したJSPファイルを環境に適用するため、 Web Application Server を再起動してください。

再起動後、プログラムをメニューに設定します。

5.1.3.1. メニュー設定

  1. テナント管理者でログインし、次のメニューを設定します。

  2. [テナント管理]-[メニュー]画面を開きます。

  3. フォルダを作成します。

    ../../_images/javaEE_1.png
  4. 作成したフォルダの下にメニューアイテムを新規作成し、URLに< protection.jsp >を設定します。

    ../../_images/javaEE_2.png
  5. メニュー設定は完了です。

    ../../_images/javaEE_3.png

5.1.4. プログラムの実行と確認

メニューで「 protection 」を選択することにより、作成したプログラムが実行されます。

実行後は intra-mart Accel Platform サーバの< C:/temp >ディレクトリに、処理されたPDFファイル「 out.pdf 」が出力されます。

PDFビューア( Adobe Acrobat Reader など)でファイルが正しく表示されることを確認し、このチュートリアルは完了です。

5.1.5. サンプルプログラムの場所

機能毎のサンプルプログラムを< %PDFMAKEUP%/sample/java >に用意しています。

使用用途に対応するフォルダの例は、次の通りです。

  • < %PDFMAKEUP%/sample/java >直下のフォルダ群

    No. 用途 サンプルフォルダ
    1 パスワード付与 /samplesetproperty
    2 パスワード解除 /samplesetproperty
    3 PDFファイルの 重ね合わせ /samplemerge
    4 PDFファイルに 透かしの挿入 /sampletrans
    5 用紙サイズの変更 /sampleedit
    6 PDFファイルの 結合 /samplecomb
    7 PDFファイルの 抽出・分割 /sampleextractpage、/samplediv
    8 PDFファイルの 回転 /samplediv
    9 PDFファイルへの 印影付与 /sampleiod、/sampletrans、/sample1
    10 PDFファイルへの 文字・画像追記 /sampletrans、/sample1
    11 PDFファイルへの しおり・リンク付与 /sampleol、/sample1
    12 PDFファイルへの フォーム・注釈追加 /sampleform、/samplenote
    13 PDFファイルへの JavaScriptの挿入 /sample1

コラム

機能に合わせて< %PDFMAKEUP%/sample/data >にサンプルデータを用意しています。

サンプルプログラムを実行する際に使用してください。