카테고리 없음

pdf 파일을 jpg파일로 변환하기

makeitworth 2022. 4. 18. 11:48

편집과 색인이 불가능한, 이미지 형태로 저장된 pdf 파일에서 텍스트를 추출하는 작업을 하고 있다.

OCR을 활용해 추출했지만, 원본 pdf 파일의 글자가 흐린 경우, 당연하게도 문자인식이 잘 되지 않는다.

문제 해결을 위해 pdf 를 jpg로 바꾼 다음, opencv 라이브러리를 통한 처리를 활용해 보다 선명한 텍스트 이미지를 만들어 보려고 시도중.

 

pdf2image 라이브러리를 활용하려 했지만, 에러 발생

PDFInfoNotInstalledError: Unable to get page count. Is poppler installed and in PATH?

 

검색해보니 poppler 설치가 필요하다고 한다.

윈도우즈에서 poppler를 설치하려면?

https://github.com/oschwartz10612/poppler-windows/releases/

위 깃허브에서 압축파일을 다운받아 원하는 경로에 압축을 풀어준다.

그리고 convert_from_path 메소드의 파라미터로 poppler_path에 경로를 입력하면, 파일 경로를 찾지 못해서 생기는 오류를 없앨 수 있다.

from pdf2image import convert_from_path

 
# Store Pdf with convert_from_path function
images = convert_from_path(pdf경로', poppler_path="poppler 있는 경로")

for i in range(len(images)):
      # Save pages as images in the pdf
    images[i].save('page'+ str(i) +'.jpg', 'JPEG')