2013-08-16 1 views
0

다음 코드를 사용하여 JOD를 사용하여 .doc를 .pdf로 변환합니다.JODConverter 문제 및 헤드리스 모드에서 LibreOffice 실행

File inputFile = new File("document.doc"); 
File outputFile = new File("document.pdf"); 

// connect to an OpenOffice.org instance running on port 8100 
OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 
connection.connect(); 

// convert 
DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 
converter.convert(inputFile, outputFile); 

// close the connection 
connection.disconnect(); 

는하지만 헤드리스 (headless) 모드에서 LibreOffice와를 시작하는 별도

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 

를 실행해야합니다.

프로그래밍 방식으로 LibreOffice를 시작하는 방법이 있습니까? 또는 변환을 수행하기 위해 LibreOffice 폴더의 경로를 JOD에 줄 수는 없습니까?

+0

JODconverter 3.0 필요한 경우, http://code.google.com/p/jodconverter/wiki/GettingStarted를 참조 LibreOffice와 시작하는 방법을 갖고있는 것 같아요. –

답변

0

한 가지 방법은 자바 프로세스와

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 

당신의 cmd를 명령을 감싸 SO에 this 질문을 참조하는 것입니다.

File inputFile = new File("document.doc"); 
File outputFile = new File("document.pdf"); 

String[] args = {"cmd","/c","\\path to libreoffice executable","-headless", "-accept='socket,host=127.0.0.1,port=8100;urp;'", "-nofirststartwizard"}; 

try{ 
    Runtime rt = Runtime.getRuntime(); 
    ProcessBuilder pb = new ProcessBuilder(args); 
    Process pr = pb.start(); 

    // connect to an OpenOffice.org instance running on port 8100 
    OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); 
    connection.connect(); 
}catch{Exception e){ 
} 

// convert 
DocumentConverter converter = new OpenOfficeDocumentConverter(connection); 
converter.convert(inputFile, outputFile); 

// close the connection 
connection.disconnect(); 

그것은 임시가 아닌 테스트 솔루션했지만 작동 될 수 있습니다

솔루션이 될 수 있습니다. 또 다른 옵션은 Windows에서 배치 파일을 만들거나 cmd 명령으로 linux에서 쉘 스크립트를 만들고 Windows 또는 Linux 로그인에서 자동 시작되도록 설정하는 것입니다. 그 후에 코드를 실행하면 ...

+0

왜'cmd' 안에 libreoffice를 감싸고 있습니까? 이것은 불필요합니다. –

0

doc 파일을 PDF로 변환하는 데는 JOD가 필요하지 않습니다. 이 직접 LibreOffice와 함께 수행 할 수 있습니다

libreoffice --headless --convert-to pdf document.doc 
관련 문제