xpdf를 활용하여 pdf 이미지 변환 텍스트추출 및 페이지수 확인하기
파일명을 보면 대략 무엇을 할 수 있는지 알 수 있습니다.
얼마나 잘 되는지 확인해 봐야겠지만 아래와 같습니다. pdf의 텍스트 추출하기 이미지변환 html변환등 일반적으로 필요할것 같은것은 모두 지원합니다. 안탑갑게도 한글을 사용하는 우리는 잘 되는지 추가적인 확인이 필요합니다.
xpdf-tools-linux-4.03/bin64/pdftotext
xpdf-tools-linux-4.03/bin64/pdfinfo
xpdf-tools-linux-4.03/bin64/pdftopng
xpdf-tools-linux-4.03/bin64/pdfimages
xpdf-tools-linux-4.03/bin64/pdftoppm
xpdf-tools-linux-4.03/bin64/pdftops
xpdf-tools-linux-4.03/bin64/pdfdetach
xpdf-tools-linux-4.03/bin64/pdffonts
xpdf-tools-linux-4.03/bin64/pdftohtml
● 아마존 리눅스2 xpdf 설치
[root@pabburi /usr/local/src/xpdf] yum install -y xpdf
[root@pabburi /usr/local/src/xpdf] pdfinfo
pdfinfo version 0.26.5
Copyright 2005-2014 The Poppler Developers - http://poppler.freedesktop.org
Copyright 1996-2011 Glyph & Cog, LLC
Usage: pdfinfo [options] <PDF-file>
-f <int> : first page to convert
-l <int> : last page to convert
-box : print the page bounding boxes
-meta : print the document metadata (XML)
-js : print all JavaScript in the PDF
-rawdates : print the undecoded date strings directly from the PDF file
-enc <string> : output text encoding name
-listenc : list available encodings
-opw <string> : owner password (for encrypted files)
-upw <string> : user password (for encrypted files)
-v : print copyright and version info
-h : print usage information
-help : print usage information
--help : print usage information
-? : print usage information
사이트와 확인해 보니 버전 차이가 납니다.
그래서 아래와 같이 사이트에서 바이너리를 받아 사용하기로 하였습니다.
이런 경우는 흔하디 흔합니다. 이미지매직같이 많이 사용하는것은 아무래도 최신버전이 압축이나 기타 지원하는것들 뿐만 아니라 버그문제도 있을 수 있으니 최신 버전을 받아 사용해야 되는 것들이 있을 수 있습니다.
● xpdf 다운로드
wget https://dl.xpdfreader.com/xpdf-tools-linux-4.03.tar.gz
tar xvfz xpdf-tools-linux-4.03.tar.gz
버전을 확인해 봅니다.
[root@pabburi /usr/local/src/xpdf] xpdf-tools-linux-4.03/bin64/pdfinfo
pdfinfo version 4.03 [www.xpdfreader.com]
Copyright 1996-2021 Glyph & Cog, LLC
Usage: pdfinfo [options] <PDF-file>
-f <int> : first page to convert
-l <int> : last page to convert
-box : print the page bounding boxes
-meta : print the document metadata (XML)
-rawdates : print the undecoded date strings directly from the PDF file
-enc <string> : output text encoding name
-opw <string> : owner password (for encrypted files)
-upw <string> : user password (for encrypted files)
-cfg <string> : configuration file to use in place of .xpdfrc
-v : print copyright and version info
-h : print usage information
-help : print usage information
--help : print usage information
-? : print usage information
----------------------------------------------------------------------
-f <int> : 변환할 첫 번째 페이지
-l <int> : 변환할 마지막 페이지
-box : 페이지 경계 상자를 인쇄합니다.
-meta : 문서 메타데이터(XML) 인쇄
-rawdates : PDF 파일에서 디코딩되지 않은 날짜 문자열을 직접 인쇄합니다.
-enc <string> : 출력 텍스트 인코딩 이름
-opw <string> : 소유자 암호(암호화된 파일의 경우)
-upw <string> : 사용자 비밀번호(암호화된 파일의 경우)
-cfg <string> : .xpdfrc 대신 사용할 구성 파일
xpdf를 활용하여 pdf 이미지 변환 텍스트추출 및 페이지수 확인하기 하기 위해서 간혹 페이지에 대한 정보를 먼저 알아야 되는 경우가 있습니다. 이럴때 이 pdfinfo 프로그램을 실행해서 필요한 정보을 알아내어 전체 페이지수가 얼마가 되는지 너무 많으면 100페이지까지만 할지등에 대한 조건을 정할때 사용이 됩니다.