翻譯|使用教程|編輯:李顯亮|2020-10-28 10:52:22.240|閱讀 289 次
概述:本文將介紹如何調用冰藍云Spire.Cloud.Word Java ConverApi接口,將word文件轉換為PDF格式。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
你在尋找一款既能在線編輯office文件,又能實現與web應用程序對接的軟件嗎?好巧,冰藍公司最新推出Spire.Cloud,搭載了基于云端的Office在線編輯器和WEB API開發接口,既能安全穩定地實現WEB網頁端在線查看、編輯Office文檔;又能在服務器端通過代碼調用接口簡單高效地實現讀寫Office文檔內容。
Spire.Cloud.Word Java SDK給開發人員提供了WordDocumentApi接口,支持創建Word文檔和獲取文檔對象。你可以點擊下載Spire.Cloud Web SDK。
本文將介紹如何調用冰藍云Spire.Cloud.Word Java ConverApi接口,將word文件轉換為PDF格式。首先,請通過Maven倉庫安裝Spire.Cloud.Word jar包及依賴。其次,需要在冰藍云官網(//cloud.e-iceblue.cn/)注冊賬號,創建我的應用程序,獲得 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); //創建ConvertAPI實例 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"; //當系統上沒有安裝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文檔轉換為其他格式: public static void convertFunction() throws ApiException { //輸入的Word文檔名字 String name = "Sample.docx"; //要轉換的目的文檔格式 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); } }
冰藍云為每個賬戶提供了2G免費內存,在”文檔管理” 目錄下面可以看到示例文檔以及轉換成功的PDF文檔效果圖:
示例文檔:
效果圖:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn