from pdf2image import convert_from_path def get_page_image( # pdf 按页切成图片 hash_value: str ) -> Dict[int, str]: pdf_path = os.path.join(config.PDF_DIR, f‘{hash_value}.pdf‘).replace(‘\\‘, ‘/‘) img_pages = convert_from_path(pdf_path) res = {} for page, img in enumerate(img_pages): arr = np.array(img) basename = f‘{hash_value}_{page:03d}.jpg‘ image_path = os.path.join(config.PDF_IMAGE_DIR, basename) img.save(image_path) res[page] = image_path return res
pdfpath = os.path.join(config.PDF_DIR, paper_id + ".pdf") xmlpath = os.path.join(config.PDF_XML_DIR, paper_id + "_{}_pdfminer.xml".format(page)) if not os.path.exists(xmlpath): os.system("pdf2txt.py -o {} -p {} -t xml {}".format(xmlpath, page + 1, pdfpath))
https://pdfminersix.readthedocs.io/en/latest/tutorial/commandline.html
原文:https://www.cnblogs.com/Mint-diary/p/14841847.html