JAVA实现Word、rtf等转PDF

该博客介绍了如何使用Java进行文件转换,特别是将Word和RTF格式的文档转换为PDF。通过引入aspose-words-jdk16-14.6.0.0.jar库,并设置许可证,可以实现不同文档格式间的互换,如DOC, DOCX, RTF到PDF的转换。转换过程中,如果未验证许可证,生成的PDF可能会带有水印。
摘要由CSDN通过智能技术生成

JAVA实现Word、rtf等转PDF

https://repository.aspose.com/repo/
下载
aspose-words-jdk16-14.6.0.0.jar

public static boolean getLicense() {  
        boolean result = false;  
        try {  
            InputStream is = BTest.class.getClassLoader().getResourceAsStream("license.xml"); // license.xml应放在..\WebRoot\WEB-INF\classes路径下  
            License aposeLic = new License();  
            aposeLic.setLicense(is);  
            result = true;  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
        return result;  
    }
public static void docToPdf(String inPath, String outPath) {  
        /*if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生  
            return;  
        }  */
        try {  
            File file = new File(outPath); // 新建一个空白pdf文档  
            FileOutputStream os = new FileOutputStream(file);  
            Document doc = new Document(inPath); // inPath是将要被转化的文档地址 
            doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,// EPUB, XPS, SWF 相互转换  
        } catch (Exception e) {  
            e.printStackTrace();  
        }  
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值