java_poi教程.pdf,如何使用POI转换.DOC / .DOCX为PDF在Java ..?

how to convert ms-document to PDF, is there any example pls share

with me.. thanks.

解决方案

If you are requiered to use POI i guess you should take a look at org.apache.poi.hwpf.converter

I never tried this, but i guess it´s worth a try atleast.

It seems like you can use WordToFoConverterto convert your XWPFDocument to a FO-file (example here).

From there you can use apaches FOP to transform the FO-file to a PDF like this:

// Step 1: Construct a FopFactory

// (reuse if you plan to render multiple documents!)

FopFactory fopFactory = FopFactory.newInstance();

// Step 2: Set up output stream.

// Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).

OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("C:/Temp/myfile.pdf")));

try {

// Step 3: Construct fop with desired output format

Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

// Step 4: Setup JAXP using identity transformer

TransformerFactory factory = TransformerFactory.newInstance();

Transformer transformer = factory.newTransformer(); // identity transformer

// Step 5: Setup input and output for XSLT transformation

// Setup input stream

Source src = new StreamSource(new File("C:/Temp/myfile.fo"));

// Resulting SAX events (the generated FO) must be piped through to FOP

Result res = new SAXResult(fop.getDefaultHandler());

// Step 6: Start XSLT transformation and FOP processing

transformer.transform(src, res);

} finally {

//Clean-up

out.close();

}

This Code was taken from https://xmlgraphics.apache.org/fop/0.95/embedding.html incase you want to read more on this topic.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值