Skip to content

Instantly share code, notes, and snippets.

@massyah
Created May 3, 2017 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save massyah/bfa5bddde978b0f2f3cb6721b0032336 to your computer and use it in GitHub Desktop.
Save massyah/bfa5bddde978b0f2f3cb6721b0032336 to your computer and use it in GitHub Desktop.
Split a pdf by page, rasterise and downsample each page
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