hermanncain 2020-06-25
import spire.cloud.pdf.sdk.*; import spire.cloud.pdf.sdk.api.PdfConvertApi; public class PDFtoWord { static String appId = "App ID"; static String appKey = "App Key"; static String baseUrl= "https://api.e-iceblue.cn"; static Configuration configuration = new Configuration(appId, appKey, baseUrl); static PdfConvertApi pdfConvertApi=new PdfConvertApi(configuration); public static void main(String[] args) throws ApiException{ String name = "sample.pdf";//PDF源文档 //PDF转Word(支持Docx/Doc) String destFilePath = "output/PDFtoWord.docx"; String format = "Docx"; /*//PDF转Html String destFilePath = "output/PDFtoHtml.html"; String format = "Html";*/ /*//PDF转PCL String destFilePath = "output/PDFtoPCL.pcl"; String format = "Pcl";*/ /*//PDF转SVG String destFilePath = "output/PDFtoSVG.svg"; String format = "Svg";*/ /*//PDF转PS String destFilePath = "output/PDFtoPS.ps"; String format = "Ps";*/ /*//PDF转XPS String destFilePath = "output/PDFtoXPS.xps"; String format = "Xps";*/ /*//PDF转PNG String destFilePath = "output/PDFtoPng.png"; String format = "Png";*/ String folder ="input";//源文档所在文件夹 String storage = null;//冰蓝云配置的2G免费存储空间,可设置为null String password = null;//源文档密码(无密码可设置为null) //调用方法将PDF转为指定文档格式 pdfConvertApi.convert(name,destFilePath,format,folder,storage,password); } }
【示例2】将XPS转为Word(支持Docx、Doc)、Html、PDF、SVG、PS、PCL、PNG
import spire.cloud.pdf.sdk.ApiException; import spire.cloud.pdf.sdk.Configuration; import spire.cloud.pdf.sdk.api.PdfConvertApi; public class XPStoWord { static String appId = "App ID"; static String appKey = "App Key"; static String baseUrl= "https://api.e-iceblue.cn"; static Configuration configuration = new Configuration(appId, appKey, baseUrl); static PdfConvertApi pdfConvertApi = new PdfConvertApi(configuration); public static void main(String[] args) throws ApiException { String name = "test.xps";//XPS源文档 //XPS转Word(支持Docx、Doc) String destFilepath = "output/XPStoDocx.docx";//结果文档路径 String format = "Docx"; /*//XPS转Html String destFilepath = "output/XPStoHtml.html";//结果文档路径 String format = "Html"; */ /*//XPS转SVG String destFilepath = "output/XPStoSVG.svg";//结果文档路径 String format = "Svg"; */ /*//XPS转PCL String destFilepath = "output/XPStoPCL.pcl";//结果文档路径 String format = "Pcl"; */ /*//XPS转PS String destFilepath = "output/XPStoPS.ps";//结果文档路径 String format = "Ps";*/ /*//XPS转PNG String destFilepath = "output/XPStoPNG.png";//结果文档路径 String format = "Png";*/ /*//XPS转PDF String destFilepath = "output/XPStoPDF.pdf";//结果文档路径 String format = "Pdf";*/ String folder = "input";//源文档所在文件夹 String storage = null; String password = null; //调用方法转换XPS文件为指定文档格式 pdfConvertApi.convert(name, destFilepath, format, folder, storage, password); } }
文档转换结果如下,注意转为SVG格式时,将源文档的每一页作为一个单独的svg文件保存,当源文档为多页时,在转换结果时会默认生成一个文件夹放置svg文件:
(完)