Created
May 3, 2019 10:57
-
-
Save sanryuu/2a88e0d5e96fd970171c33dcea0fbba2 to your computer and use it in GitHub Desktop.
A4の日光企画用隠しノンブル入れスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://qiita.com/ukyo/items/4a0f697c332343d77659 | |
#!/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 improving-self-esteem.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`); | |
// 余白を入れる | |
// execSync(`cpdf -mediabox "-${MARGIN}mm -${MARGIN}mm ${WIDTH + MARGIN * 2}mm ${HEIGHT + MARGIN * 2}mm" tmp/merged.pdf -o book-release.pdf`); | |
// execSync("rm -rf tmp"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment