Transfer Doc to Pdf on Ubuntu System

Transfer Doc to Pdf on Ubuntu System

1. Command
Using command line to transfer doc to pdf
>unoconv -f pdf sprint9_Additional_Information.doc

When I am executing this command with none-root user. I got this error messages:
Error: Unable to connect or start own listener. Aborting.

So, I su to root user, it is ok. It is said that it can also transfer other formats. But I do not have
chance to have a try.
unoconv -f doc other-document.odt
unoconv -f jpg some-image.png
unoconv -f xsl some-spreadsheet.csv

We can use command to see all the supporting format.
>unoconv --show

2. Start the openoffice service and execute in Java class
start the service
>soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard

we can get the opensource jar packages here
http://www.artofsolving.com/opensource/jodconverter
http://sourceforge.net/projects/jodconverter/files/

The Java class will be as follow:
package com.chinacreator.test;


import java.io.File;

import java.net.ConnectException;


import com.artofsolving.jodconverter.DocumentConverter;

import com.artofsolving.jodconverter.openoffice.connection.OpenOfficeConnection;

import com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection;

import com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter;


public class JOD4DocToPDF {


public void docToPdf(File inputFile, File outputFile) {

long start = System.currentTimeMillis();

// connect to an OpenOffice.org instance running on port 8100

OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100);

try {

connection.connect();

DocumentConverter converter = new OpenOfficeDocumentConverter(

connection);

converter.convert(inputFile, outputFile);

} catch (ConnectException e) {

e.printStackTrace();

} finally {

// close the connection

if (connection != null) {

connection.disconnect();

connection = null;

}

}

long end = System.currentTimeMillis();

System.out.println("converted from " + inputFile.getName() + " to "

+ outputFile.getName() + " time:" + (end - start) + " ms.");

}


class TestThread extends java.lang.Thread {

public File inputFile;

public File outputFile;


public void run() {

JOD4DocToPDF job = new JOD4DocToPDF();

job.docToPdf(inputFile, outputFile);

System.out.println(outputFile.getName() + " converting start.");

}

}


public void test() {

TestThread t1 = new TestThread();

t1.inputFile = new File("/var/tmp/c1.doc");

t1.outputFile = new File("/var/tmp/c1.pdf");


TestThread t2 = new TestThread();

t2.inputFile = new File("/var/tmp/c2.doc");

t2.outputFile = new File("/var/tmp/c2.pdf");


t2.start();

t1.start();

}


public static void main(String[] args) throws Exception {

JOD4DocToPDF p = new JOD4DocToPDF();

p.test();

}

}

There is some problem on ubuntu, maybe it is right on windows.

references:
http://ubuntuwriter.blogspot.com/2008/12/pdf.html
http://www.iteye.com/topic/352103
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值