Skip to content

Instantly share code, notes, and snippets.

@alamsal
Last active July 31, 2022 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alamsal/bdfa7528cc9bd291e527 to your computer and use it in GitHub Desktop.
Save alamsal/bdfa7528cc9bd291e527 to your computer and use it in GitHub Desktop.
Create thumbnails from pdf using Python
#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