Created
July 5, 2019 10:33
-
-
Save imbdb/dff9f58056c5fbfa6e049afe7d21f645 to your computer and use it in GitHub Desktop.
Extract PDF pages as PNG
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
# 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