それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

複数JPEGをPDFに統合する(merge jpegs to one pdf)

複数画像を一枚のPDFにするには

OSX で複数画像を一枚のPDFにするには。

がある。

convert *.jpg out.pdf

これが一番楽。

しかしファイルサイズが。。。

左がAutomator。右がConvertコマンド。ファイルサイズがやたらと大きい。

(pdf)

圧縮オプションを使う。

convert *.jpg -compress out.pdf

Automator ジョブをコマンドラインで使うには

Automator の複数PDFをPDFに合成するコマンドの実態は次にある。

cat "/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py"

なんとPythonで出来ている。

Automator の中身はPythonで書かれているファイルもあるんですね

#! /usr/bin/python
#
# join
#   Joing pages from a a collection of PDF files into a single PDF file.
#
#   join [--output <file>] [--shuffle] [--verbose]"
#
#   Parameter:
#
#   --shuffle
#	Take a page from each PDF input file in turn before taking another from each file.
#	If this option is not specified then all of the pages from a PDF file are appended
#	to the output PDF file before the next input PDF file is processed.
#
#   --verbose
#   Write information about the doings of this tool to stderr.
#
import sys
import os
import getopt
import tempfile
import shutil
from CoreFoundation import *
from Quartz.CoreGraphics import *


これをそのまま使えばいいと分かる。

画像をPDFにするコマンド

#!/usr/bin/env ruby
# coding : utf-8
files = ARGV.map{|e|
  tmp = File.dirname(e) + "/"+  File.basename(e,File.extname(e)) + ".pdf"
  cmd = "convert '#{e}' '#{tmp}'"
 `#{cmd}`
  tmp
}

`"/System/Library/Automator/Combine PDF Pages.action/Contents/Resources/join.py" -o out.$(date -I).pdf  #{files.join(' ')}`

files.each{|e|
  File.unlink e
}