String htmFileName;//获取转换成PDF之后文件名if(".doc".equals(type)){ htmFileName= fileName+".pdf"; }elseif(".docx".equals(type)){ htmFileName= fileName+".pdf"; }else{returnnull; }//通过转换之后的PDF文件名,创建PDF文件File htmlOutputFile =newFile(toFilePath + File.separatorChar +htm...
public static void main(String []args) throws Exception { String sourcePath = "C:\\Users\\Administrator\\Desktop\\1\\分组情况一览表.xls"; String destFile = "C:\\Users\\Administrator\\Desktop\\1\\dest.pdf"; int flag = Converter.office2PDF(sourcePath,destFile); if (flag == 1) { S...
步骤三:保存pdf文件 最后,你需要将生成的pdf文件保存到指定路径。使用以下代码保存pdf文件: // 创建File对象FileoutputFile=newFile("path/to/save/pdf/file.pdf");// 将PDDocument对象保存为pdf文件pdf.save(outputFile);// 关闭PDDocument对象pdf.close(); 1. 2. 3. 4. 5. 6. 7. 8. 经过以上三个步...
用jdoctopdf的实现方法如下: publicvoiddoc2pdf(String docFileName)throwsException{Stringpath=this.getSession().getServletContext().getRealPath("/")+"attachment/";Parserp=newDocParser();// create a new parser instanceFileInputStreamfis=newFileInputStream(path+"/doc/"+ docFileName +".doc");/...
java:19) This file seems to be a binary doc/ppt/xls, not an encrypted OLE2 file containing a doc/pptx/xlsx “此文件似乎是一个二进制文件doc/ppt/xls,而不是包含doc/pptx/xlsx的加密OLE2文件,经过验证docx4j并不能完美的支持所有的word文档,至少doc文档并不能支持。不知道你们有没有遇到过这个...
Java利用openoffice将doc、docx转为pdf实例代码 本文研究的主要是java编程利用openoffice将doc、docx转为pdf的实现代码,具体如下。 1. 需要用的软件 OpenOffice , JodConverter 2.启动OpenOffice的服务 我到网上查如何利用OpenOffice进行转码的时候,都是需要先用cmd启动一个soffice服务,启动的命令是:soffice -headless -acc...
Docx4J.toPDF(pkg, new FileOutputStream(target)); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Docx4JException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } 三、转换结果
at com.convert.test.ConvertTest.main(ConvertTest.java:19)Thisfile seems to be a binary doc/ppt/xls, not an encryptedOLE2file containing a doc/pptx/xlsx “此文件似乎是一个二进制文件doc/ppt/xls,而不是包含doc/pptx/xlsx的加密OLE2文件,经过验证docx4j并不能完美的支持所有的word文档,至少doc文档...
Java word转pdf工具类 java doc 转 pdf,Word作为目前主流的文本编辑软件之一,功能十分强大,应用人群广,但是它也存在一些问题。像是Word文件在不同软件或操作平台之间传输的时候,时不时会出现各种格式的“变化”,也会有点“不稳定”,例如内容和格式经常容易篡动。相较
至此,你已经学会了使用Java将doc文件转换为pdf文件的基本流程。下面是整个过程的类图和旅程图: Conversion+readDocFile() : String+createPdfDocument() : Document+copyContentToPdf() : void+savePdfDocument() : voidDocument-text: String+Document()+addContent(text: String) : void+saveToFile() : voidJour...