Created
May 3, 2017 20:41
-
-
Save massyah/bfa5bddde978b0f2f3cb6721b0032336 to your computer and use it in GitHub Desktop.
Split a pdf by page, rasterise and downsample each page
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
import os | |
from subprocess import call | |
input_pdf = "plotCGHAnnexe.pdf" | |
for n_p in range(1, 23): | |
tgt_file = "plot_%d.pdf" % (n_p) | |
cropped_file = os.path.splitext(tgt_file)[0] + "-crop" + ".pdf" | |
downsampled = "lq_" + os.path.splitext(cropped_file)[0] + ".pdf" | |
midsampled = "hq_" + os.path.splitext(cropped_file)[0] + ".pdf" | |
call(args=["pdfjam", "plotCGHAnnexe.pdf", str(n_p), "--outfile", tgt_file]) | |
call(args=["pdfcrop.pl", "--margins", "20 20 20 20", tgt_file]) | |
call(args=["convert", "-density", "300", cropped_file, downsampled]) | |
call(args=["convert", "-density", "450", cropped_file, midsampled]) | |
print("finished %s", downsampled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment