IM-PDFCoordinator for Accel Platform プログラミングガイド 第13版 2024-04-01

8.1.2. ユーザ定義タスク

8.1.2.1. PDF変換

../../../_images/user_definition_1.png

8.1.2.1.1. 入力値

sample_pdfc_combine <object>
├─ combFile1Path <string>
├─ combFile2Path <string>
└─ outputFilePath <string>
項目名 必須/任意 配列/リスト 説明
combFile1Path
combFile2Path
必須 string なし PDF結合対象ファイルのパブリックストレージパス
outputFilePath 必須 string なし PDF結合出力ファイルのパブリックストレージパス

8.1.2.1.2. 出力値

sample_pdfc_combine <object>
├─ status <boolean>
└─ message <string>
項目名 配列/リスト 説明
status boolean なし
true:PDF結合成功時
false:PDF結合失敗時
message string なし
PDF結合成功時:空文字
PDF結合失敗時:エラーメッセージ

8.1.2.1.3. スクリプト

サンプル内で使用しているAPIについては「 API 」を参照してください。

コラム

文書情報を設定する場合は、スクリプトの81、82行目のコメントを外してください。

コラム

セキュリティ情報を設定する場合は、設定したいセキュリティの暗号化レベルに合わせて、スクリプトの次のコメントを外してください。

  • 40bit RC4 :93、94行目
  • 128bit RC4 :116、117行目
  • 128bit AES :139、140行目
  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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/**
 * run.
 *
 * @param input {Object} - task input data.
 * @return {Object} task result.
 */
function run(input) {

	const tempFiles = new IotheCommonTempFiles();

	try {
		if (!input.combFile1Path) {
			throw new Error("処理対象PDFファイルパスにnull、または、空文字が指定されています。");
		}

		if (!input.combFile2Path) {
			throw new Error("処理対象PDFファイルパスにnull、または、空文字が指定されています。");
		}

		if (!input.outputFilePath) {
			throw new Error("出力対象PDFファイルパスにnull、または、空文字が指定されています。");
		}

		if ((input.combFile1Path.indexOf('.') != -1) && (input.combFile2Path.indexOf('.') != -1)) {
			const srcFileExt1 = "." + input.combFile1Path.split('.').pop();
			const srcFileExt2 = "." + input.combFile2Path.split('.').pop();
			const tempCombFile1 = tempFiles.copyFrom(input.combFile1Path, srcFileExt1);
			const tempCombFile2 = tempFiles.copyFrom(input.combFile2Path, srcFileExt2);
			const tempOutFile = tempFiles.create();

			// IM-PDFCoordinatorを実行し、PDFファイルを結合します。
			execPdfcoordinatorCombine(tempCombFile1.path(), tempCombFile2.path(), tempOutFile.path());

			tempFiles.copyTo(tempOutFile, input.outputFilePath);

			return {
				status: true,
				message: ""
			};
		} else {
			throw new Error("処理対象PDFファイルの拡張子がありません。");
		}
	} catch (error) {
		return {
			status: false,
			message: error.message
		};
	} finally {
		tempFiles.close();
	}
}

/**
 * IM-PDFCoordinatorを実行し、PDFファイルを結合します。
 * @param {String} combFile1Path 被結合対象のファイルパス
 * @param {String} combFile2Path 結合対象のファイルパス
 * @param {String} outFilePath 結合後の出力先PDFファイルパス
 */
function execPdfcoordinatorCombine(combFile1Path, combFile2Path, outFilePath)
{
	// PDFをファイル単位で結合するクラスのインスタンスを生成します。
	// @return {Object} PDFをファイル単位で結合するクラスのインスタンス
	const comb = new pdfcombine();
	checkerror(0, comb);

	// エンコード文字列を指定します。
	comb.m_encode = "MS932";

	// 内部メンバの初期化等を行います。
	// @returns {Number} 正常時は0、エラー時は-1を返します。
	let sts = comb.init();
	checkerror(sts, comb);

	// 出力PDFの文書情報を設定します。
	// setdocinfo(title, subTitle, creator, app, keyword);
	// @param {String} title タイトルに設定する文字列を指定します。
	// @param {String} subtitle サブタイトルに設定する文字列を指定します。
	// @param {String} creator 作成者に設定する文字列を指定します。
	// @param {String} app 作成アプリケーションに設定する文字列を指定します。
	// @param {String} keyword キーワードに設定する文字列を指定します。
//	sts = comb.setdocinfo("文書タイトル", "文書サブタイトル", "作成者", "作成アプリケーション名", "キーワード");
//	checkerror(sts, comb);

	// 出力PDFのRC4 40ビットセキュリティを設定します。
	// setsecurity(fromtop, showpasswd, securitypasswd, noprint, noedit, nocopy, noaddnote);
	// @param {boolean} fromtop 連結元の先頭のPDFを引継ぎます。
	// @param {String} showpasswd 参照用のパスワードを指定します。
	// @param {String} securitypasswd セキュリティ設定用のパスワードを指定します。
	// @param {boolean} noprint 印刷(true:不可,false:可能)
	// @param {boolean} noedit 編集(true:不可,false:可能)
	// @param {boolean} nocopy 転載(true:不可,false:可能)
	// @param {boolean} noaddnote 注釈追加(true:不可,false:可能)
//	sts = comb.setsecurity(false, "open", "security", false, true, false, true);
//	checkerror(sts, comb);

	// 出力PDFのRC4 128ビットセキュリティを設定します。
	// setsecurity128(showpasswd, securitypasswd, print, access, copy, change);
	// @param {String} showpasswd 参照用のパスワードを指定します。
	// @param {String} securitypasswd セキュリティ設定用のパスワードを指定します。
	// @param {String} print 128bit security(印刷)を指定します。
	// "PRINT_DISABLE":許可しない
	// "PRINT_DEGRADED":低解像度で許可する
	// "PRINT_ENABLE":許可する
	// @param {String} access 128bit security(アクセス)を指定します。
	// "ACC_DISABLE":許可しない
	// "ACC_ENABLE":許可する
	// @param {String} copy 128bit security(転載)を指定します。
	// "COPY_DISABLE":許可しない
	// "COPY_ENABLE":許可する
	// @param {String} change 128bit security(文書変更)を指定します。
	// "DOCCHANGE_DISABLE":許可しない
	// "DOCCHANGE_ASSEMBLE":アセンブリを許可する
	// "DOCCHANGE_FORMFILL":フォーム入力を許可する
	// "DOCCHANGE_ADDNOTE":フォーム入力と注釈追加を許可する
	// "DOCCHANGE_ENABLE":許可する
//	sts = comb.setsecurity128("open", "security", "PRINT_DEGRADED", "ACC_ENABLE", "COPY_DISABLE", "DOCCHANGE_ADDNOTE");
//	checkerror(sts, comb);

	// 出力PDFのAES 128ビットセキュリティを設定します。
	// setsecurityaes128(showpasswd, securitypasswd, print, access, copy, change);
	// @param {String} showpasswd 参照用のパスワードを指定します。
	// @param {String} securitypasswd セキュリティ設定用のパスワードを指定します。
	// @param {String} print 128bit security(印刷)を指定します。
	// "PRINT_DISABLE":許可しない
	// "PRINT_DEGRADED":低解像度で許可する
	// "PRINT_ENABLE":許可する
	// @param {String} access 128bit security(アクセス)を指定します。
	// "ACC_DISABLE":許可しない
	// "ACC_ENABLE":許可する
	// @param {String} copy 128bit security(転載)を指定します。
	// "COPY_DISABLE":許可しない
	// "COPY_ENABLE":許可する
	// @param {String} change 128bit security(文書変更)を指定します。
	// "DOCCHANGE_DISABLE":許可しない
	// "DOCCHANGE_ASSEMBLE":アセンブリを許可する
	// "DOCCHANGE_FORMFILL":フォーム入力を許可する
	// "DOCCHANGE_ADDNOTE":フォーム入力と注釈追加を許可する
	// "DOCCHANGE_ENABLE":許可する
//	sts = comb.setsecurityaes128("open", "security", "PRINT_DEGRADED", "ACC_ENABLE", "COPY_DISABLE", "DOCCHANGE_ADDNOTE");
//	checkerror(sts, comb);

	// PDF出力後のWebに最適化の処理の有無を設定します。
	// 特にこのメソッドを呼び出さない場合はデフォルトで最適化されます。
	// setfastwebview(bfastwebview);
	// @param {boolean} bfastwebview true:最適化する,false:最適化しない
	sts = comb.setfastwebview(true);
	checkerror(sts, comb);

	// 出力PDFをオープンし、連結の準備をします。
	// open(outpdf);
	// @param {String} outpdf 出力先PDFのファイル名を指定します。
	sts = comb.open(outFilePath);
	checkerror(sts, comb);

	// 指定ファイルのPDF連結の準備をします。
	// combine(pdf);
	// @param {String} pdf 連結するPDFのファイル名を指定します。
	sts = comb.combine(combFile1Path);
	checkerror(sts, comb);
	sts = comb.combine(combFile2Path);
	checkerror(sts, comb);

	// 出力PDFを連結及びクローズし、連結を終了します。
	sts = comb.close();
	checkerror(sts, comb);

	// 内部のハンドルを開放します。
	comb.release();
}

/**
 * メソッドの戻り値からエラーを判定し、エラーであれば例外を投げます。
 * @param {Number} sts メソッドの戻り値
 * @param {Object} obj メソッドを実行したインスタンス
 */
function checkerror(sts, obj) {
	if (obj === null) {
		throw new Error("did not create the object");
	}
	if (sts < 0) {
		throw new Error("error code:" + obj.geterrorno() + ", error message:" + obj.geterror());
	}
}