Spire.Cloud.PDF PdfConvertApi provides an interface that can be used to convert documents into other formats PDF documents, such as Word (docx / doc), Html, XPS, SVG, PCL, PS, Png converted to PDF and XPS. Wherein the article will select several formats, for example, describes particular conversion method.
The necessary steps:
Step one: DLL file and obtain import.
Method 1. via the official website of the local download the SDK package file. (Must be registered and logged in)
After the download, unzip the file, add a reference to the VS program Spire.Cloud.Pdf.Sdk.dll file and three other dll;
Method 2. in the program by Nuget search download directly into all dll.
Introducing effect as shown below:
Step two: App ID and Key acquisition. In the cloud Create an account and create application in the "My Apps" section to obtain the App ID and App Key.
Step Three: Upload source document. In the "Document Management" section, upload the source document. Here you can build folders, documents stored in the folder. When not build folder, the source document and the resulting document directly saved in the root directory. Examples in this article, built two folders, one for storing the source document and the resulting document. (Cloud platform provides free 10,000 times the number of calls and documents 2G memory)
C # code sample
[Example 1 ] PDF turn Word (docx / DOC )
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; using System.IO; namespace PDFToWord { class PDFToDocx { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账号信息 Configuration pdfConfiguration = new Configuration(appId, appKey); PdfConvertApi pdfConverterApi = new PdfConvertApi(pdfConfiguration); string name = "sample.pdf";//源文档 string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null) string destFilePath = "pdfconversion/PDFToDocx.docx";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下) string destFilePath2 = "pdfconversion/PDFToDoc.doc"; string password = null;//设置文档密码(如果文档没有密码则设置成null) //调用方法转为Word文档格式 pdfConverterApi.ConvertPdfInStorageToDocx(name, destFilePath, folder, password); pdfConverterApi.ConvertPdfInStorageToDoc(name, destFilePath2, folder, password); } } }
【示例2】PDF转Html
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; namespace PDFToHTML { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账号信息 Configuration pdfConfiguration = new Configuration(appId, appKey); PdfConvertApi pdfConvertApi = new PdfConvertApi(pdfConfiguration); string name = "sample.pdf";//源文档 string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null) string destFilePath = "pdfconversion/PDFToHtml.html";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下) string password = null;//设置文档密码(如果文档没有密码则设置成null) //调用方法转换为HTML格式 pdfConvertApi.ConvertPdfInStorageToHtml(name,destFilePath,folder,password); } } }
【示例3】PDF转XPS
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; namespace PDFToXPS { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账号信息 Configuration pdfConfiguration = new Configuration(appId, appKey); PdfConvertApi pdfConvertapi = new PdfConvertApi(pdfConfiguration); string name = "sample.pdf";//源文档 string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null) string destFilePath = "pdfconversion/PDFToXPS.xps";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下) string password = null;//设置文档密码(如果文档没有密码则设置成null) //调用方法转为XPS pdfConvertapi.ConvertPdfInStorageToXps(name, destFilePath, folder, password); } } }
【示例4】PDF转SVG
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; namespace PDFToSvg { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账号信息 Configuration pdfConfiguration = new Configuration(appId, appKey); PdfConvertApi pdfConvertapi = new PdfConvertApi(pdfConfiguration); string name = "sample.pdf";//源文档 string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null) string destFilePath = "pdfconversion/PDFToSvg.svg";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下) string password = null;//设置文档密码(如果文档没有密码则设置成null) //调用方法转为SVG pdfConvertapi.ConvertPdfInStorageToSvg(name, destFilePath, folder, password); } } }
注:这里转为svg是将原PDF文档中的每一页单独转换为一个svg文档,如果原PDF文档包含多页,转换后默认生成一个文件夹,将生成的每一页svg放在这个文件夹下。
【示例5】PDF转PCL
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; namespace PDFToPcl { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账号信息 Configuration pdfConfiguration = new Configuration(appId, appKey); PdfConvertApi pdfConvertApi = new PdfConvertApi(pdfConfiguration); string name = "sample.pdf";//源文档 string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null) string destFilePath = "pdfconversion/PDFToPcl.pcl";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下) string password = null;//设置文档密码(如果文档没有密码则设置成null) //调用方法转换为Pcl格式 pdfConvertApi.ConvertPdfInStorageToPcl(name, destFilePath, folder, password); } } }
【示例6】PDF转PS
using System; using Spire.Cloud.Pdf.Sdk.Client; using Spire.Cloud.Pdf.Sdk.Api; namespace PDFToPs { class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账号信息 Configuration pdfConfiguration = new Configuration(appId, appKey); PdfConvertApi pdfConvertapi = new PdfConvertApi(pdfConfiguration); string name = "sample.pdf";//源文档 string folder = "input";//设置源文档所在文件夹(如果源文档在根目录下,不在文件夹中,可设置为null) string destFilePath = "pdfconversion/PDFToPs.ps";//设置转换后的目标文档路径(文档放置在pdfconversion文件夹下) string password = null;//设置文档密码(如果文档没有密码则设置成null) //调用方法转为PS pdfConvertapi.ConvertPdfInStorageToPs(name, destFilePath, folder, password); } } }
文档格式转换效果:
(本文完)