commit ad3e983587bf1824cfe698dc3570b4c2a752130b Author: Niles Rogoff Date: Sun Jun 26 14:47:40 2016 -0400 Initial commit diff --git a/JL0x7.pdf b/JL0x7.pdf new file mode 100644 index 0000000..9cd92a6 Binary files /dev/null and b/JL0x7.pdf differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..f53f731 --- /dev/null +++ b/README.md @@ -0,0 +1,26 @@ +# Pdf Reformatter + +Takes a dual pdf and turns it into a format acceptable to blurb.com for magazine distribution. + +# Usage + +It's as simple as + + pdftocairo -png [yourpdf].pdf + 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 + +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 + +Finally, just use that dpi with img2pdf to merge the images into the final pdf you're going to upload to blurb. Unfortunately the --dpi option was removed from img2pdf, however if you download and install the last version on github it will still work. To do that + + 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... + sudo python3 setup.py install + cd .. + rm -rf img2pdf diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..1a4d434 --- /dev/null +++ b/test.sh @@ -0,0 +1,11 @@ +echo Old, do not use +exit 1 +gs \ + -o test3-content.pdf \ + -sDEVICE=pdfwrite \ + -dDEVICEWIDTHPOINTS=585 -dDEVICEHEIGHTPOINTS=738 \ + -dFIXEDMEDIA \ + -dPDFSETTINGS=/prepress \ + -dPDFFitPage -r300 \ + -dCompatibilityLevel=1.4 \ + JL0x7-content.pdf diff --git a/test2.py b/test2.py new file mode 100644 index 0000000..c2f0da6 --- /dev/null +++ b/test2.py @@ -0,0 +1,14 @@ +import subprocess, glob, PIL.Image +size = "1345x1754" +subprocess.call(("convert -size "+size+" xc:white canvas.png").split()) +for f in glob.glob("*.png"): + try: + idx = int(f.split("-")[1][:2]) + except: + print("Failed for image " + f) + continue + geometry = [] + image = PIL.Image.open(f) + if idx % 2 == 0: + 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")])