("F:\\poi笔记.docx"); XWPFDocument xwpfDocument = new XWPFDocument(fileInputStream); PdfOptions pdfOptions = PdfOptions.create(); FileOutputStream fileOutputStream = new FileOutputStream("F:\\poi笔记.pdf"); PdfConverter.getInstance().convert(xwpfDocument,fileOutputStream,pdfOptions); fileInput...
第一步 添加maven依赖 需注意:此处引用的版本为2.2.1版本,不支持.docx文件的转换,若需要转换.docx文件需2.2.2及以上版本,但maven库没有此版本需自行下载导入jar包 com.artofsolving jodconverter 2.2.1 第二步 编写后台代码 // word文件路径 String sourceFile = “C:\\Users\\dev\\Desktop\\template.docx”...
converter.convert(inputFile, outputFile); // 关闭连接 connection.disconnect(); // 关闭进程 p.destroy(); } public static void main(String[] args) { String start = "F:\\新建文件夹\\我是word测试文件.docx"; String over = "F:\\新建文件夹\\成了.pdf"; try { WordToPDF(start, over); ...
connect(); // 转换word到pdf DocumentConverter converter = new OpenOfficeDocumentConverter( connection); converter.convert(inputFile, outputFile); System.out.println("转换完成!"); } catch (Exception e) { e.printStackTrace(); } finally { if (connection != null) { // 关闭连接 connection....
*将Office文档转换为PDF. 运行该函数需要用到OpenOffice, OpenOffice * * @param sourceFile * 源文件,绝对路径. 可以是Office2003-2007全部格式的文档, Office2010的没测试. 包括.doc, .docx, .xls, .xlsx, .ppt, .pptx等. * * @param destFile ...
byte[] imgBytes = ConvertImgToBase64Util.image2Bytes(imgPath); Image image = Image.getInstance(imgBytes); appearance.setSignatureGraphic(image); //设置认证等级 appearance.setCertificationLevel(PdfSignatureAppearance.NOT_CERTIFIED); //印章的渲染方式,这里选择只显示印章 ...
(connection); converter.convert(sourceFile, pdfFile); connection.disconnect(); System.out.println("---第二步:转换为PDF格式 ,路径:" + pdfFile.getPath()); } catch (java.net.ConnectException e) { e.printStackTrace(); System.out.println("---OpenOffice服务未启动"); try { throw e; } cat...
* @param pdfFile void */ public static void convert2PDF(String inputFile, String pdfFile) { String suffix = getFileSufix(inputFile); if (suffix.equals("doc") || suffix.equals("docx") || suffix.equals("txt")) { word2PDF(inputFile, pdfFile); ...
pdfGenerator.generatePDFFromDocxURL("http://your_url_here.docx","c:/pdfgenerator-test1.pdf","A4","Portrait"); Here you can find major details on convertingDocx to PDF in Java with the Sferyx PDF Generator. Convert Word Docx to PDF in Java from URL to java.io.OutputStream ...
public void convert(File docFile, File destFile) { try { documentConverter.convert(docFile).to(destFile).execute(); } catch (OfficeException e) { log.error("openoffice文件转换pdf失败,源文件:{},异常信息:",docFile.getPath(),e);