Skip to content

Instantly share code, notes, and snippets.

@imbdb
Created July 5, 2019 10:33
Show Gist options
  • Save imbdb/dff9f58056c5fbfa6e049afe7d21f645 to your computer and use it in GitHub Desktop.
Save imbdb/dff9f58056c5fbfa6e049afe7d21f645 to your computer and use it in GitHub Desktop.
Extract PDF pages as PNG
# Uses convert cmdline tool
import os
def main():
dir_list = os.listdir('./pdfs') # change to your pdf directory
for full_file_name in dir_list:
base_name, extension = os.path.splitext(full_file_name)
if extension == '.pdf': # then .pdf file --> convert to image!
cmd_str = ' '.join(['convert',
'"./pdfs/' + full_file_name + '"', # change to your pdf directory
'"' + base_name + '.png"'])
print(cmd_str) # echo command to terminal
os.system(cmd_str) # execute command
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment