Created
April 29, 2018 08:29
-
-
Save kmuto/5a3221577eb0d439d92167ce2da6e6f8 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# InDesign、TeXのB5変/A5のトンボ版をSONY DPT-RP1向けに実寸調整する | |
# Copyright 2018 Kenshi Muto | |
# | |
# TeXのトンボ値はGreenCherry社由来のトンボ設定に依存しており、別のトンボ実装の場合は異なる値になる可能性がある | |
# | |
# pdflatex、pdfinfo(Poppler)が利用できるようにしておく | |
require 'yaml' | |
require 'tmpdir' | |
scale = nil | |
if ARGV.size < 2 || ARGV.size > 3 || !File.exist?(ARGV[0]) | |
puts <<EOT | |
sony-resize.rb トンボ付き元PDF 保存先PDF [スケール値] | |
EOT | |
exit | |
end | |
size = YAML.load(`pdfinfo #{ARGV[0]}`).fetch("Page size").sub(/\spts.*/, '') | |
size = size.sub(/\.\d+ x /, 'x').sub(/\.\d+\Z/, '') | |
case size | |
when '589x802' | |
puts "仕上がりB5正寸、InDesign" | |
scale = 1.095 | |
when '589x734' | |
puts "仕上がりB5変(233mm)、InDesign" | |
scale = 1.087 | |
when '595x841' | |
puts "仕上がりB5変(233mm)、TeX (A4出力)" | |
scale = 1.1 | |
when '493x668' | |
puts "仕上がりA5正寸、InDesign" | |
scale = 0.908 | |
when '515x728' | |
puts "仕上がりA5正寸、TeX (B5出力)" | |
scale = 0.952 | |
else | |
unless ARGV[2] | |
puts "どのサイズにも当てはまりませんでした (#{size})。3つめの引数でスケールを指定してください。" | |
exit | |
end | |
end | |
if ARGV[2] | |
scale = ARGV[2].to_f | |
if scale <= 0 | |
puts 'スケール値が異常です。' | |
exit | |
end | |
end | |
targetpdf = File.expand_path(ARGV[0]) | |
savepdf = File.expand_path(ARGV[1]) | |
Dir.mktmpdir('sonyresize') do |tmpdir| | |
Dir.chdir(tmpdir) | |
File.write('r.tex', <<EOT | |
\\pdfinclusioncopyfonts=1 | |
\\documentclass{article} | |
\\usepackage[paper=a4paper]{geometry} | |
\\usepackage{pdfpages} | |
\\begin{document} | |
\\includepdf[pages=-,scale=#{scale}]{#{targetpdf}} | |
\\end{document} | |
EOT | |
) | |
system('pdflatex -interaction=batchmode -halt-on-error r.tex') | |
FileUtils.mv 'r.pdf', savepdf | |
end | |
puts "#{ARGV[1]} を作成しました。" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment