openoffice将word转成pdf及添加水印

系统维护需求,需要将word转成pdf,上一篇博客是把word2003的模板升级成word2007模板,因为旧模板生成的word为xml格式转成pdf后内容不对,在网上搜寻了很久linux系统相关支持,发现了openoffice4.
参考:openoffice安装和卸载
https://blog.csdn.net/lx_nhs/article/details/99305227
https://blog.csdn.net/zhou920786312/article/details/79964040
启动openoffice
linux下:

cd /opt/openoffice4/program 

 ./soffice "-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" -nologo -headless -nofirststartwizard &

查看是否启动
ps -ef | grep openoffice
贴上部分java代码word转成pdf

 public  boolean officeToPDF(String sourceFile, String destFile) {
   
		        try {
   

		            File inputFile = new File(sourceFile);
		           // Writer out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(inputFile), "UTF-8")); 
		            
		            if (!inputFile.exists()) {
   
		                // 找不到源文件, 则返回false
		                return false;
		            }
		            // 如果目标路径不存在, 则新建该路径
		            File outputFile = new File(destFile);
		            if (!outputFile.getParentFile().exists()) {
   
		                outputFile.getParentFile().mkdirs();
		            }
		            //如果目标文件存在,则删除
		            if (outputFile.exists()) {
   
		                outputFile.delete();
		            }
		            
		            
/*		            Document document = new Document();
		            document.loadFromFile("Sample.docx");
		            //保
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值