Converting a PDF to a series of images with Python

前端 未结 5 2092
执念已碎
执念已碎 2020-11-30 00:18

I\'m attempting to use Python to convert a multi-page PDF into a series of JPEGs. I can split the PDF up into individual pages easily enough with available tools, but I have

5条回答
  •  感情败类
    2020-11-30 00:50

    Here's whats worked for me using the python ghostscript module (installed by '$ pip install ghostscript'):

    import ghostscript
    
    def pdf2jpeg(pdf_input_path, jpeg_output_path):
        args = ["pdf2jpeg", # actual value doesn't matter
                "-dNOPAUSE",
                "-sDEVICE=jpeg",
                "-r144",
                "-sOutputFile=" + jpeg_output_path,
                pdf_input_path]
        ghostscript.Ghostscript(*args)
    

    I also installed Ghostscript 9.18 on my computer and it probably wouldn't have worked otherwise.

提交回复
热议问题