Switched from pdftocairo to imagemagik convert

This commit is contained in:
Niles Rogoff 2016-07-06 19:51:26 -04:00
parent 0a81a4d524
commit 70f6e4bc12
2 changed files with 7 additions and 5 deletions

View File

@ -6,13 +6,15 @@ Takes a dual pdf and turns it into a format acceptable to blurb.com for magazine
It's as simple as
pdftocairo -png [yourpdf].pdf
convert -density 300 [yourfile].pdf [yourfile]-%03d.png
python3 test2.py
img2pdf --dpi 156 *-2.png -o final.pdf
Ok so maybe not really.
You must open one of the images and verify its resolution, as well as the dimensions of the smallest image with an aspect ratio of 0.766666667 that could contain it. Put those dimensions in `size` in test2.py
Pick any "density" to render the pdf at, the general concensus is that you shouldn't print anything at under 300 dpi. 300 dpi looks fine from 10-12 inches away. Larger dpis will take longer and take more ram. I tried one at 600 dpi and it would oom crash until I had loaded 30 gigabytes of swap. I canceled it when it didn't complete in an hour
After exporting as an image, you must open one of the images and verify its resolution, as well as identify the dimensions of the smallest image with an aspect ratio of 0.766666667 that could contain it. Put those dimensions in `size` in test2.py
After running test2.py, you need to open one of the images ending in -2.png (or just use the size you found in the last step), and determine the number of pixels per inch needed to make the image 8.625 x 11.25 inches. I recommend a calculator for this one
@ -20,7 +22,7 @@ Finally, just use that dpi with img2pdf to merge the images into the final pdf y
git clone https://github.com/josch/img2pdf
cd img2pdf
git co 06d90eea154629213a529fb0cae3f832d225c0e8 # As of the time of writing, this is the head of master, but just to future-proof everything...
git co 06d90eea154629213a529fb0cae3f832d225c0e8 # As of the time of writing, this is the head of master, but just in case..
sudo python3 setup.py install
cd ..
rm -rf img2pdf

View File

@ -1,5 +1,5 @@
import subprocess, glob, PIL.Image
size = "1345x1754"
size = "3138x4093"
subprocess.call(("convert -size "+size+" xc:white canvas.png").split())
for f in glob.glob("*.png"):
try:
@ -9,6 +9,6 @@ for f in glob.glob("*.png"):
continue
geometry = []
image = PIL.Image.open(f)
if idx % 2 == 0:
if idx % 2 == 1:
geometry = ["-geometry", "+" + str( int(size.split("x")[0]) - image.width ) + "+0"]
subprocess.call(["convert", "-compress", "none", "canvas.png", f, *geometry, "-composite", f.replace(".png", "-2.png")])