Java轉換Word檔案到PDF檔案

來源:互聯網
上載者:User

標籤:png   setting   ack   https   image   except   ext   ring   throws   

使用Docx4j將Word檔案轉換為PDF檔案:

public static void convertDocxToPDF(String docxFilePath, String pdfPath) throws Exception {                OutputStream os = null;        try {            // 負載檔案             File docx = new File(docxFilePath);            InputStream is = new FileInputStream(docx);            WordprocessingMLPackage mlPackage = WordprocessingMLPackage.load(is);            // 字型轉換            Mapper fontMapper = new IdentityPlusMapper();            fontMapper.put("華文行楷", PhysicalFonts.get("STXingkai"));            fontMapper.put("華文仿宋", PhysicalFonts.get("STFangsong"));            fontMapper.put("華文宋體", PhysicalFonts.get("STSong"));            fontMapper.put("華文中宋", PhysicalFonts.get("STZhongsong"));            fontMapper.put("隸書", PhysicalFonts.get("LiSu"));            fontMapper.put("宋體", PhysicalFonts.get("SimSun"));            fontMapper.put("微軟雅黑", PhysicalFonts.get("Microsoft Yahei"));            fontMapper.put("黑體", PhysicalFonts.get("SimHei"));            fontMapper.put("楷體", PhysicalFonts.get("KaiTi"));            fontMapper.put("新宋體", PhysicalFonts.get("NSimSun"));            fontMapper.put("宋體擴充", PhysicalFonts.get("simsun-extB"));            fontMapper.put("仿宋", PhysicalFonts.get("FangSong"));            fontMapper.put("仿宋_GB2312", PhysicalFonts.get("FangSong_GB2312"));            fontMapper.put("幼圓", PhysicalFonts.get("YouYuan"));            mlPackage.setFontMapper(fontMapper);            //            os = new FileOutputStream(pdfPath);            FOSettings foSettings = Docx4J.createFOSettings();            foSettings.setWmlPackage(mlPackage);            Docx4J.toFO(foSettings, os, Docx4J.FLAG_EXPORT_PREFER_XSL);        } catch (Exception ex) {            ex.printStackTrace();        } finally {            IOUtils.closeQuietly(os);        }    }

 官網地址:https://www.docx4java.org/forums/

支援Word、Excel、PPT:

 

轉換Word為PDF,依賴於Plutext,官網地址:http://converter-eval.plutext.com/

Plutext為商業軟體包,提供180天試用。

此外可以使用FO,該方式免費。

webapp.docx4java.org/OnlineDemo/docx_to_pdf.html?_ga=2.226968541.1700223194.1521458163-1699339587.1517224689

 

Java轉換Word檔案到PDF檔案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.