8.1.2. ユーザ定義タスク¶
8.1.2.1. PDF変換¶
入力値¶
im_cookbook_8004_user <object>
├─ inputFilePath <string>
└─ outputFilePath <string>
| 項目名 | 必須/任意 | 型 | 配列/リスト | 説明 | 
|---|---|---|---|---|
| inputFilePath | 必須 | string | なし | PDF変換対象ファイルのパブリックストレージパス | 
| outputFilePath | 必須 | string | なし | PDF変換出力ファイルのパブリックストレージパス | 
出力値¶
im_cookbook_8004_user <object>
├─ status <boolean>
└─ message <string>
| 項目名 | 型 | 配列/リスト | 説明 | 
|---|---|---|---|
| status | boolean | なし | true:PDF変換成功時 
false:PDF変換失敗時 
 | 
| message | string | なし | PDF変換成功時:空文字 
PDF変換失敗時:エラーメッセージ 
 | 
スクリプト¶
サンプル内で使用しているAPIについては「 API 」を参照してください。
コラム
文書情報を設定する場合は、スクリプトの27、32行目のコメントを外してください。
コラム
セキュリティ情報を設定する場合は、スクリプトの35、41行目のコメントを外してください。
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  | /**
 * run.
 *
 * @param input {Object} - task input data.
 * @return {Object} task result.
 */
function run(input) {
  const tempFiles = new PdfaTempFiles();
  try {
    if (!input.inputFilePath) {
      throw new Error("PDF変換対象ファイルパスにnull、または、空文字が指定されています。");
    }
    if (!input.outputFilePath) {
      throw new Error("PDF変換出力ファイルパスにnull、または、空文字が指定されています。");
    }
    if (input.inputFilePath.indexOf('.') != -1) {
      const ex = new IMPDFAutoConverter();
      const srcFileExt = "." + input.inputFilePath.split('.').pop();
      const tempSrcFile = tempFiles.copyFrom(input.inputFilePath, srcFileExt);
      const tempOutFile = tempFiles.create();
      /* 文書情報を設定 */
      /* ex.setDocInf(
        "タイトル",
        "サブタイトル",
        "作成者",
        "アプリケーション",
        "キーワード"); */
      /* 128ビットセキュリティ情報を設定 */
      /* ex.setSecurity128(
        "open",
        "sec",
        "PRINT_DISABLE",
        "ACC_DISABLE",
        "COPY_DISABLE",
        "DOCCHANGE_DISABLE"); */
      /* Web用に最適化の有無を設定 */
      ex.setFastWebView(true);
      /* プリンタ名を設定 */
      ex.setPrinter("YSS PDF Converter XP");
      /* 変換前のタイムアウト秒数を設定 */
      ex.setBeforeTimeoutSec(0);
      /* 変換後のタイムアウト秒数を設定 */
      ex.setTimeoutSec(1500);
      /* PDF変換サーバへのファイル転送のタイムアウトミリ秒を設定 */
      ex.setTransTimeoutMilliSec(1560000);
      /* PDF変換 */
      ex.convert(tempSrcFile.path(), tempOutFile.path());
      tempFiles.copyTo(tempOutFile, input.outputFilePath);
    } else {
      throw new Error("PDF変換対象ファイルの拡張子がありません。");
    }
  } catch (error) {
    return {
      status: false,
      message: error.message
    };
  } finally {
    tempFiles.close();
  }
  return {
    status: true,
    message: ""
  };
}
 |