翻譯|使用教程|編輯:李顯亮|2020-10-28 10:52:22.240|閱讀 289 次
概述:本文將介紹如何調(diào)用冰藍(lán)云Spire.Cloud.Word Java ConverApi接口,將word文件轉(zhuǎn)換為PDF格式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
你在尋找一款既能在線編輯office文件,又能實(shí)現(xiàn)與web應(yīng)用程序?qū)拥能浖幔亢们桑{(lán)公司最新推出Spire.Cloud,搭載了基于云端的Office在線編輯器和WEB API開發(fā)接口,既能安全穩(wěn)定地實(shí)現(xiàn)WEB網(wǎng)頁端在線查看、編輯Office文檔;又能在服務(wù)器端通過代碼調(diào)用接口簡單高效地實(shí)現(xiàn)讀寫Office文檔內(nèi)容。
Spire.Cloud.Word Java SDK給開發(fā)人員提供了WordDocumentApi接口,支持創(chuàng)建Word文檔和獲取文檔對象。你可以點(diǎn)擊下載Spire.Cloud Web SDK。
本文將介紹如何調(diào)用冰藍(lán)云Spire.Cloud.Word Java ConverApi接口,將word文件轉(zhuǎn)換為PDF格式。首先,請通過Maven倉庫安裝Spire.Cloud.Word jar包及依賴。其次,需要在冰藍(lán)云官網(wǎng)(//cloud.e-iceblue.cn/)注冊賬號,創(chuàng)建我的應(yīng)用程序,獲得 APP ID 及 App Key。
import spire.cloud.word.sdk.client.*; import spire.cloud.word.sdk.client.api.ConvertApi; import spire.cloud.word.sdk.client.model.PrivateFont; import java.util.ArrayList; import java.util.List; public class CloudWord { //配置賬號信息 static String appId = "App ID"; static String appKey = "App Key"; static String baseUrl = "http://api.e-iceblue.cn"; static Configuration wordConfiguration = new Configuration(appId, appKey, baseUrl); //創(chuàng)建ConvertAPI實(shí)例 static ConvertApi convertApi = new ConvertApi(wordConfiguration); public static void main(String[] args) throws Exception { //輸入的Word文檔名字 String name = "Sample.docx"; //輸入Word文檔的密碼 String password = null; //輸入的文檔所在的文件夾 String folder = "input"; String storage = null; //輸出的pdf文檔的完整路徑 String destFilePath = "Result1203.pdf"; //當(dāng)系統(tǒng)上沒有安裝Word文檔中使用的字體時,可以通過加載字體文件將字體到pdf文檔中,以便正確的繪制文本 List privateFonts = new ArrayList(); privateFonts.add(new PrivateFont("黑體", "input/simhei.ttf")); privateFonts.add(new PrivateFont("consola", "input/consola.ttf")); convertApi.convertToPdf(name, destFilePath, password, folder, storage, privateFonts); } //將Word文檔轉(zhuǎn)換為其他格式: public static void convertFunction() throws ApiException { //輸入的Word文檔名字 String name = "Sample.docx"; //要轉(zhuǎn)換的目的文檔格式 String format = "xps";//postScript, pcl, dot, dotx, dotm, docm, odt, wordxml, wordml, pdf, doc, docx, rtf, epub, xps, html String password = null; //輸入文檔所在的文件夾 String folder = "input"; String storage = null; //輸出文檔的完整路徑 String destFilePath = "output/result.xps"; convertApi.convert(name, format, destFilePath, password, folder, storage); } }
冰藍(lán)云為每個賬戶提供了2G免費(fèi)內(nèi)存,在”文檔管理” 目錄下面可以看到示例文檔以及轉(zhuǎn)換成功的PDF文檔效果圖:
示例文檔:
效果圖:
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn