from pdf2image import convert_from_path import os def qietu(fname): dirname = fname.rsplit('.', 1)[0] if not os.path.exists(dirname): os.mkdir(dirname) images = convert_from_path(fname, fmt='png', output_folder=dirname, poppler_path=r'/opt/homebrew/Cellar/poppler/23.10.0/bin') return images if __name__ == '__main__': pdfile = 'huanbu.pdf' qietu(pdfile)