본문 바로가기

개발자이야기/JAVA이야기

xls,ppt to pdf (openoffice 활용)

반응형

출처 : http://yang2s.tistory.com/entry/CentOs-OpenOffice-%EC%84%A4%EC%B9%98-%EB%B0%8F-%EC%84%9C%EB%B2%84-%EC%8B%A4%ED%96%89


ppt 파일을 pdf로 변환 하기 위해 OpenOffice를 사용 하게 되었는데....

서버에 설치를 먼저 해야 했다.

서버의 종류는 CentOs 

먼저 http://openoffice.or.kr/main/page.php?id=download 에서 리눅스 RPM 버전을 다운 받는다.

적당한 위치에 다운 받은 파일을 업로드 하고 

OOo_3.3.0_Linux_x86_install-rpm_ko.tar.gz 파일 압축을 풀어 준다.

작업은 루트로 작업 한다. 

# tar zxvf OOo_3.3.0_Linux_x86_install-rpm_ko.tar.gz 

# cd OOO330_m20_native_packed-1_ko.9567/RPMS

압축이 풀린 경로로 이동한다.

#rpm -i *.rpm

설치 한다. 

# cd desktop-integration

경로로 이동한다. 

자신의 OS에 맞는 것을 설치 하면 되는데  

cenos는 

openoffice.org3.3-redhat-menus-3.3-9556.noarch.rpm을 설치 한다. 

# rpm -i openoffice.org3.3-redhat-menus-3.3-9556.noarch.rpm

# soffice -headless -accept="socket,host=localhost,port=8100;urp;" -nofirststartwizard& 서버를 실행 시켜준다.

/usr/lib/openoffice/program/soffice.bin X11 error: Can't open display: 
Set DISPLAY environment variable, use -display option
or check permissions of your X-Server
(See "man X" resp. "man xhost" for details)

이런 에러가 발생 하면 

unset XAUTHORITY
DISPLAY=:1000
export DISPLAY
killall Xvfb
Xvfb $DISPLAY &

이렇게 한번씩 처 주고 

# soffice -headless -accept="socket,host=localhost,port=8100;urp;" -nofirststartwizard& 다시 실행 시켜준다

# ps -ef | grep openoffice 프로세스가 잘 올라 왔는지 확인 한다.

간단한 예제를 작성 해서 파일 변환이 잘 되는지 확인 하면 되는데 

JODConverter 2.2.2 버전(http://sourceforge.net/projects/jodconverter/files/JODConverter/) 을 다운 받는다

압축을 풀어 주고 lib 경로에 있는 jar 파일들을 java가 설치 되어 있는 

자바홈/jre/lib/ext 경로에 복사 해 준다. 

# cp *.jar /usr/local/java/jre/lib/ext
 
테스트 자바 파일

TestJod.java

import java.io.*;
import com.artofsolving.jodconverter.openoffice.connection.*;
import com.artofsolving.jodconverter.openoffice.converter.*;
import com.artofsolving.jodconverter.*;


public class TestJod {
 
  public static void main(String[] args) throws Exception {
   
   try{
    OpenOfficeConnection OOconnection = new SocketOpenOfficeConnection(8100);
         OOconnection.connect();
   
         String file = "101787320427.ppt"; //< ----- 변환대상 ppt  파일명


         String new_file_name = null;
         new_file_name = file.substring(0, file.indexOf(".")) + ".pdf";

   
         File inFile = new File(file);
         File outFile = new File(new_file_name);

  

         // the conversion
         DocumentConverter PDFconverter = new OpenOfficeDocumentConverter(OOconnection);
         PDFconverter.convert(inFile, outFile);
         OOconnection.disconnect();
   }catch(Exception e){
    System.out.println("---"+e);
   }
      
        
        
  }  

}

컴파일후 실행 하면 pdf 파일이 생성되어 있는것으 확인 할수 있다.

반응형

'개발자이야기 > JAVA이야기' 카테고리의 다른 글

java 기본 강의 좋은 블로그  (0) 2014.12.01
한글깨짐 현상 처리  (0) 2014.09.01
poi 관련  (0) 2014.07.15
serialVersionUID 생성하기  (0) 2014.07.01
Serializable 과 transient 의미와 사용법  (0) 2014.07.01