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....
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); ...
第二步 编写后台代码 // word文件路径 String sourceFile = “C:\\Users\\dev\\Desktop\\template.docx”; // 生成的pdf路径 String destFile = “C:\\Users\\dev\\Desktop\\generate.pdf”; try { File inputFile = new File(sourceFile); // 如果目标路径不存在, 则新建该路径 File outputFile = ...
converter.convert(inputFile, outputFile);// close the connectionconnection.disconnect(); } 方法2的截图(格式基本一致,有错位) 方法3:效果最好的一种方法,但是需要window环境,而且速度是最慢的需要安装msofficeWord以及SaveAsPDFandXPS.exe(word的一个插件,用来把word转化为pdf) Office版本是2007,因为SaveAsPDFandXPS...
text.pdf.PdfWriter; public class WordToPdfConverter { public static void convertToPdf(String inputFilePath, String outputFilePath) { try { // 加载Word文档 FileInputStream fis = new FileInputStream(inputFilePath); XWPFDocument document = new XWPFDocument(fis); // 创建PDF文档 Document pdfDoc = ...
public void convert(String input, String output){ File inputFile = new File(input); File outputFile = new File(output); OpenOfficeConnection connection = new SocketOpenOfficeConnection(8100); try { connection.connect(); DocumentConverter converter = new OpenOfficeDocumentConverter(connection); ...
converter.convert(inputFile, outputFile); // 关闭连接 connection.disconnect(); // 关闭进程 p.destroy(); } public static void main(String[] args) { String start = "F:\\新建文件夹\\我是word测试文件.docx"; String over = "F:\\新建文件夹\\成了.pdf"; ...
Java利用OpenOffice将word等office文档转换成PDF 1. 需要用的软件 OpenOffice 下载地址http://www.openoffice.org/ JodConverter 下载地址http://sourceforge.net/projects/jodconverter/files/JODConverter/,也可以直接从附件里面下载 https:///sbraconnier/jodconverter 有维护地址。
Convert Word Docx to PDF in Java from URL to java.io.File This method will convert the Docx to PDF and will generate the file using the standard page format string such as "A4", "Letter" etc. and and save the file to the specified OutputStream or File and page orientation such as ...
// Load the source PDF fileConverterconverter=newConverter("resume.pdf");// Set the convert optionsWordProcessingConvertOptionsconvertOptions=newWordProcessingConvertOptions();// Convert PDF to DOCXconverter.convert("resume.docx",convertOptions); ...