Scantailor images to PDF for POD services on Linux
Posted: 18 Dec 2012, 17:44
Print On Demand services require PDF files in specific page sizes. Scantailor, does not have the option of creating a specfic size. Here's how I add margins to Scantailor output and make PDFs to submit to Lulu or another POD service. A key to this process is to make the inner margins larger than the outer. It is necessary, because the loss of space in the gutter of a printed book. In this tutorial, I have used an extra half inch in the inner margin.
Software used: libtiff-tools and imagemagick (debian package names -- in other distros, it's just libtiff)
All commands are run from the directory in which the output files are located. My files are numbered. The image sizes listed in my commands are if the images are 600 DPI. Adjust as necessary. While it may look complicated, the commands can be run with a single command if placed in a shell script for each page size. Try doing that with Acrobat with a single command!(A more elegand solution would be to add input variables when running the script, but I've never taken the time to do it)
Steps 1 and 5 are optional. I prefer to do them, because I like to preserve the original scantailor output.
1. copy output to a temporary folder
$mkdir print && cp *.tif print && cd print
2. create even and odd folders and move images into them before processing
$mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds
3. using imagemagick, add margins to even and odd images with a larger inner margin. (This example is a 6"x9" target size, with an extra half inch in the gutter. Adjust variables as necessary)
$cd odds && mogrify -verbose -gravity center -extent 3300x5400 -gravity east -extent 3600x5400 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3300x5400 -gravity west -extent 3600x5400 *.tif && mv *.tif .. && cd .. && rmdir evens odds
4. using libtif, make a pdf file of the now correctly-sized images
$tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif
5. clean temporary files and move pdf to original directory
$rm *.tif && mv print.pdf .. && cd .. && rmdir print
Pocket 4.25"x6.875" (2550x4125)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 2250x4125 -gravity east -extent 2550x4125 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 2250x4125 -gravity west -extent 2550x4125 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
A5 5.833"x8.264" (3500x4958)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3200x4958 -gravity east -extent 3500x4958 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3200x4958 -gravity west -extent 3500x4958 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Trade 6"x9" (3600x5400)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3300x5400 -gravity east -extent 3600x5400 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3300x5400 -gravity west -extent 3600x5400 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Royal 6.139"x9.21" (3683x5526)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3383x5526 -gravity east -extent 3683x5526 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3383x5526 -gravity west -extent 3683x5526 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Crown Quarto 7.444"x9.681" (4466x5809)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 4166x5809 -gravity east -extent 4466x5809 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 4166x5809 -gravity west -extent 4466x5809 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Comic 6.625"x10.25" (3975x6150)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3675x6150 -gravity east -extent 3975x6150 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3675x6150 -gravity west -extent 3975x6150 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Letter 8.5"x11" (5100x6600)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 4800x6600 -gravity east -extent 5100x6600 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 4800x6600 -gravity west -extent 5100x6600 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
A4 8.264"x11.694" (4958x7016)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 4658x7016 -gravity east -extent 4958x7016 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 4658x7016 -gravity west -extent 4958x7016 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Software used: libtiff-tools and imagemagick (debian package names -- in other distros, it's just libtiff)
All commands are run from the directory in which the output files are located. My files are numbered. The image sizes listed in my commands are if the images are 600 DPI. Adjust as necessary. While it may look complicated, the commands can be run with a single command if placed in a shell script for each page size. Try doing that with Acrobat with a single command!(A more elegand solution would be to add input variables when running the script, but I've never taken the time to do it)
Steps 1 and 5 are optional. I prefer to do them, because I like to preserve the original scantailor output.
1. copy output to a temporary folder
$mkdir print && cp *.tif print && cd print
2. create even and odd folders and move images into them before processing
$mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds
3. using imagemagick, add margins to even and odd images with a larger inner margin. (This example is a 6"x9" target size, with an extra half inch in the gutter. Adjust variables as necessary)
$cd odds && mogrify -verbose -gravity center -extent 3300x5400 -gravity east -extent 3600x5400 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3300x5400 -gravity west -extent 3600x5400 *.tif && mv *.tif .. && cd .. && rmdir evens odds
4. using libtif, make a pdf file of the now correctly-sized images
$tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif
5. clean temporary files and move pdf to original directory
$rm *.tif && mv print.pdf .. && cd .. && rmdir print
Pocket 4.25"x6.875" (2550x4125)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 2250x4125 -gravity east -extent 2550x4125 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 2250x4125 -gravity west -extent 2550x4125 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
A5 5.833"x8.264" (3500x4958)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3200x4958 -gravity east -extent 3500x4958 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3200x4958 -gravity west -extent 3500x4958 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Trade 6"x9" (3600x5400)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3300x5400 -gravity east -extent 3600x5400 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3300x5400 -gravity west -extent 3600x5400 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Royal 6.139"x9.21" (3683x5526)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3383x5526 -gravity east -extent 3683x5526 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3383x5526 -gravity west -extent 3683x5526 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Crown Quarto 7.444"x9.681" (4466x5809)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 4166x5809 -gravity east -extent 4466x5809 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 4166x5809 -gravity west -extent 4466x5809 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Comic 6.625"x10.25" (3975x6150)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 3675x6150 -gravity east -extent 3975x6150 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 3675x6150 -gravity west -extent 3975x6150 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
Letter 8.5"x11" (5100x6600)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 4800x6600 -gravity east -extent 5100x6600 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 4800x6600 -gravity west -extent 5100x6600 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print
A4 8.264"x11.694" (4958x7016)
mkdir print && cp *.tif print && cd print && mkdir evens odds && mv *[02468].tif evens && mv *[13579].tif odds && cd odds && mogrify -verbose -gravity center -extent 4658x7016 -gravity east -extent 4958x7016 *.tif && mv *.tif .. && cd .. && cd evens && mogrify -verbose -gravity center -extent 4658x7016 -gravity west -extent 4958x7016 *.tif && mv *.tif .. && cd .. && rmdir evens odds && tiffcp *.tif print.tif && tiff2pdf -o print.pdf print.tif && rm *.tif && mv print.pdf .. && cd .. && rmdir print