I use an Automator application to move pdf files to a directory, then copy them to another directory, then convert the copy into a thumbnail using only the 1st page, with the file name remaining exactly the same as the original except with a .png extension instead of .pdf
I had this working under Mavericks, but it stopped working when I upgraded to Mojave, then I eventually got it to work again using the solution here. How to render only first page in PDF as image and then resize?
Now I'm trying to upgrade to Monterey, and it's broken again, and I can't figure it out this time.
Any ideas would be awesome. If possible, I'd like to come up with a solution that Apple won't break every couple years, but experience has taught me that is unlikely.
I've been messing with this for days.
Screenshot of my application attached below.
And here is the complete script I'm using.
#! /usr/bin/python # import sys import os import tempfile from Quartz.CoreGraphics import * from os.path import splitext from os.path import basename from os.path import join def createPDFDocumentWithPath(path): return CGPDFDocumentCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, path, len(path), False)) def main(argv): for input_pdf_filename in argv: doc = createPDFDocumentWithPath(input_pdf_filename) page_one = CGPDFDocumentGetPage(doc, 1) mediaBox = CGPDFPageGetBoxRect(page_one, kCGPDFMediaBox) if CGRectIsEmpty(mediaBox): mediaBox = None file_name, extension = splitext(basename(input_pdf_filename)) output_path = join(tempfile.gettempdir(), file_name + extension) writeContext = CGPDFContextCreateWithURL(CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, output_path, len(output_path), True), None, None) CGContextBeginPage(writeContext, mediaBox) CGContextDrawPDFPage(writeContext, page_one) CGContextEndPage(writeContext) CGPDFContextClose(writeContext) del writeContext print output_path if __name__ == "__main__": main(sys.argv[1:])