PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, May 6, 2022

[FIXED] How to convert all pdf files in a directory/folder to image python 3?

 May 06, 2022     image, pdf, python     No comments   

Issue

How to convert all pdf files in a directory/folder to image python 3? is there any alternative?

while running this code i m getting an error like

pdf2image.exceptions.PDFPageCountError: Unable to get page count. Syntax Warning : May not be a PDF file (continuing anyway) Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't find trailer dictionary Syntax Error: Couldn't read xref table

I dono why please someone help me

from pdf2image import convert_from_path
import glob,os
import os, subprocess

pdf_dir = r"C:\\Users\\xxx\\Desktop\\folder1\\folder2\\"
os.chdir(pdf_dir)

for pdf_file in os.listdir(pdf_dir):
    pages = convert_from_path(pdf_file, 500)
    for page in pages:
        page.save(pdf_file[:-4] +".jpg", 'JPEG')

Solution

I think you've both JPG and PDF in the same directory. To iterate over only PDF files:

from pdf2image import convert_from_path
import glob,os
import os, subprocess

pdf_dir = r"C:\\Users\\xxx\\Desktop\\folder1\\folder2\\"
os.chdir(pdf_dir)

for pdf_file in glob.glob(os.path.join(pdf_dir, "*.pdf")):
    pages = convert_from_path(pdf_file, 500)
    for page in pages:
        page.save(pdf_file[:-4] +".jpg", 'JPEG')


Answered By - Madhan Varadhodiyil
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing