こちらを、パクらせていただきました https://qiita.com/ukyo/items/4a0f697c332343d77659
Reviewのディレクトリ内で、node relaese.js
cpdfのインストールは、上のQiitaを参考に。
こちらを、パクらせていただきました https://qiita.com/ukyo/items/4a0f697c332343d77659
Reviewのディレクトリ内で、node relaese.js
cpdfのインストールは、上のQiitaを参考に。
| #!/usr/bin/env node | |
| const { execSync } = require("child_process"); | |
| const fs = require("fs"); | |
| // 環境に合わせて設定を変更する | |
| // B5は WIDTH = 182; HEIGHT = 257; | |
| const PAGE_START = 1; | |
| const WIDTH = 148; | |
| const HEIGHT = 210; | |
| const MARGIN = 30; | |
| execSync("rm -rf tmp"); | |
| execSync("mkdir -p tmp"); | |
| // バラして | |
| execSync("cpdf -split book.pdf -o tmp/%%%.pdf"); | |
| // 隠しノンブル入れて | |
| const files = fs.readdirSync("tmp").sort(); | |
| files.forEach((file, i) => { | |
| const page = file.split(".").shift(); | |
| const nombre = ((+page + PAGE_START - 1) + "").split("").join("\\n"); | |
| const pos = [`${MARGIN/2+2}mm ${HEIGHT /2 + MARGIN/2 +8}mm`, `${WIDTH + MARGIN/2}mm ${HEIGHT /2 + MARGIN/2 +8}mm`][i % 2]; | |
| execSync(`cpdf -add-text "${nombre}" -pos-left "${pos}" -font "Courier" -font-size "6" tmp/${file} -o tmp/${page}-nombre.pdf`); | |
| }); | |
| // マージし直して | |
| execSync(`cpdf -merge ${files.map(f => f.replace(/(\d{3})/, "tmp/$1-nombre")).join(" ")} -o book_relaese.pdf`); | |