본문 바로가기
Linux

GhostScript , Ghost4j를 이용한 PDF TO TIFF 변환 예제 입니다

by Hwoarang757 2020. 1. 8.


출처 : https://www.ghostscript.com
다운로드 링크 : https://www.ghostscript.com/download/gsdnld.html
라이선스 : https://www.ghostscript.com/license.html
[ 듀얼 라이선스 (GNU AGPL + 상용 허가 예외) ]

9.50 버젼 설치 예시를 간단하게 작성 하였습니다.

인터넷 연결이 불가능 한 상황에서 GhostScript 홈페이지 Download 링크 에서
Ghostscript 9.50 Source for all platforms 파일 tar.gz 파일을 받아
CentOS 서버에 파일을 반입하여 설치 진행 해보았습니다.


1. CentOS GhostScript 설치
(1) opt 디렉터리에 ghostscript-9.50.tar.gz 파일 이동
# cd /opt/
(2) 앞축 해제
# tar xvf ghostscript-9.50.tar.gz

(3) 설치 진행
# cd ghostscript-9.50
# ./configure
# make
# make install
(4) 설치 된 GhostScript 버젼 확인
# gs -version



2. ghost4j 설치 진행
출처 : http://www.ghost4j.org/
다운로드 링크 : http://www.ghost4j.org/downloads.html

- ghost4j.jar Interpreter Command 만 호출 시에 의존성 존재 JAR 확인 진행

- jna-4.1.0.jar
- log4j-1.2.17.jar (버젼은 관계 없는 걸로 추정 됩니다. )


public static void convertPdf2ImgGhost(String filePath) {
//get Ghostscript instance
Ghostscript gs = Ghostscript.getInstance();

//prepare Ghostscript interpreter parameters with display device
Calendar cal = Calendar.getInstance();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String dateString = dateFormat.format(cal.getTime());

String[] gsArgs = new String[8];
gsArgs[0] = "-q";
gsArgs[1] = "-r204x196";
gsArgs[2] = "-sDEVICE=tiffg4";
gsArgs[3] = "-sCompression=g4";
gsArgs[4] = "-dNOPAUSE";
gsArgs[5] = "-dBATCH";
gsArgs[6] = String.format("-sOutputFile=D:/%s.tif",dateString);
gsArgs[7] = "D:/Sample/test2.pdf";
//run PostScript (also works with PDF) and exit interpreter
try {
gs.initialize(gsArgs);
gs.exit();
Ghostscript.deleteInstance();
} catch (GhostscriptException e) {
System.out.println("ERROR: " + e.toString());
} catch(Exception exception) {
System.out.println("ERROR: " + exception.getMessage());
}
}

- Windows 의 경우에 CLASSPATH 참조 필요
- gs9.50\bin 디렉터리 참조 필요 ( 설치 디렉터리 )
- gsdll64.dll , gsdll64.lib , gswin64.exe , gswin64c.exe