大家,早安,
我想将多个 1 页 PDF 转换为 TIF 或 PNG 格式。所有 PDF 都位于同一个文件夹中。我听说 TIF 有点棘手,所以我想将 PNG 作为第二种选择。该文件夹中每个 .PDF 的输出应该是一个 .TIF/.PNG。我想将图像保存在第二个文件夹中,并且图像的标题 (PDF/TIF) 应该与原始 PDF 相同。
这是我用于另一种情况的代码。我没有遍历一个装满 PDF 的文件夹,而是单独转换了每个 PDF。此外,这些 PDF 文件由多页而不是一页组成,这就是为什么有一个计数器。我不需要这个,因为新的 PDFS 只包含一页。一个一个地去太费时间了,因为这次我有大量的 1 页 PDF。我该如何调整这个?可悲的是,我在编程方面不是很有经验。
> from pdf2image import convert_from_path import os
>
> outputDir = "imag/PNG_Files/"
>
> def convert (file, outputDir):
> if not os.path.exists(outputDir):
> os.makedirs(outputDir)
>
> pages = convert_from_path(file, 200)
> counter = 1
> for page in pages:
> myfile = outputDir + 'output' + str(counter) + '.png'
> counter = counter + 1
> page.save(myfile, "PNG")
> print(myfile)
>
> file = r"U:\DEV\Folder1\PDFs\Document.pdf"
>
> convert(file, outputDir)
任何帮助表示赞赏!
问候
米恩