xlogI125’s blog

パソコン作業を効率化したい

Acrobat JavaScript練習 テスト用にPDFを作成

メモ

テスト用にPDFを作成する

使い捨てスクリプト

// Acrobat Standard DC (2022年5月頃), Windows 11
// JavaScript デバッガー の コンソール から実行
// 実行方法はテキストを範囲選択して Ctrl + Enter

(() => {
  var x, y;
  var x1, y1, x2, y2;
  var w, h;
  var rgbR, rgbG, rgbB;
  var annot;

  const docNew = app.newDoc();

  [x1, y1, x2, y2] = [0, 0, 297, 210];

  const boxC = [x1, y2, x2, y1].map( x => x * 72 / 25.4 );
  const boxM = [0, boxC[1] - boxC[3], boxC[2] - boxC[0], 0];

  docNew.setPageBoxes({cBox: "Crop", rBox: boxC});
  docNew.setPageBoxes({cBox: "Media", rBox: boxM});
  docNew.setPageBoxes({cBox: "Art"});
  docNew.setPageBoxes({cBox: "Trim"});
  docNew.setPageBoxes({cBox: "Bleed"});

  h = 10;
  w = 11;

  for (y = 0; y < 210; y += h) {
    for (x = 0; x < 297; x += w) {
      rgbR = Math.random();
      rgbG = Math.random();
      rgbB = Math.random();

      x1 = x * 72 / 25.4;
      y1 = y * 72 / 25.4;
      x2 = x1 + w * 72 / 25.4;
      y2 = y1 + h * 72 / 25.4;

      annot = docNew.addAnnot({
        page: 0, type: "Square", 
        rect: [x1, y1, x2, y2], 
        style: "S", borderEffectStyle: "", 
        strokeColor: ["RGB", 0, 0, 0], 
        opacity: 1.0, width: 0, 
        fillColor: ["RGB", rgbR, rgbG, rgbB], 
        author: "", subject: "", 
        modDate: new Date(2020, 0, 2, 3, 4, 5)
      });
    }
  }

  docNew.flattenPages();

})();