Last active
July 31, 2022 01:18
-
-
Save alamsal/bdfa7528cc9bd291e527 to your computer and use it in GitHub Desktop.
Create thumbnails from pdf using Python
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
#Install Ghost script before python package's installation from: http://www.a-pdf.com/convert-to-pdf/gs.exe | |
from wand.image import Image | |
from wand.display import display | |
fileDirectory = "D:/files/" | |
inFileName="infile.pdf" | |
outFileName="outfile.png" | |
imageFromPdf = Image(filename=fileDirectory+inFileName) | |
pages = len(imageFromPdf.sequence) | |
print(pages) | |
image = Image( | |
width=imageFromPdf.width, | |
height=imageFromPdf.height * pages | |
) | |
for i in range(pages): | |
image.composite( | |
imageFromPdf.sequence[i], | |
top=imageFromPdf.height * i, | |
left=0 | |
) | |
image.format="png" | |
image.save(filename=fileDirectory+outFileName) | |
display(image) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment