Java converts PDF/XPS to Word/html/SVG/PS/PCL/PNG, PDF and XPS interoperability

Keywords: Java PCL SDK Maven OkHttp

Spire.Cloud.SDKFor Java provides the interface PdfConvertApi to convert PDF and XPS documents into specified document formats by converting (), such as converting PDF to Word (Docx, Doc), Html, XPS, SVG, PS, PCL, PNG, and converting XPS to Word (Docx, Doc), Html, PDF, SVG, PS, PCL, PNG, etc.).The text will show you how to do this through Java examples.First, refer to the following steps to prepare the program running environment:
1. Import the jar file.(There are two ways)
(Recommended) Mode 1. Create a Maven project program by maven warehouse Download the import.Take IDEA for example, create a new Maven project inPom.xmlConfigure the Maven repository path in the file and specifySpire.cloud.sdkDependencies are as follows:

<repositories>
    <repository>
        <id>com.e-iceblue</id>
        <name>cloud</name>
        <url>http://repo.e-iceblue.cn/repository/maven-public/</url>
    </repository>
</repositories>

<dependencies>
        <dependency>
            <groupId> cloud </groupId>
            <artifactId>spire.cloud.sdk</artifactId>
            <version>3.5.0</version>
        </dependency>

        <dependency>
        <groupId> com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.1</version>
        </dependency>

        <dependency>
            <groupId> com.squareup.okhttp</groupId>
            <artifactId>logging-interceptor</artifactId>
            <version>2.7.5</version>
        </dependency>

        <dependency>
            <groupId> com.squareup.okhttp </groupId>
            <artifactId>okhttp</artifactId>
            <version>2.7.5</version>
        </dependency>

        <dependency>
            <groupId> com.squareup.okio </groupId>
            <artifactId>okio</artifactId>
            <version>1.6.0</version>
        </dependency>

        <dependency>
            <groupId> io.gsonfire</groupId>
            <artifactId>gson-fire</artifactId>
            <version>1.8.0</version>
        </dependency>

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.18</version>
        </dependency>

        <dependency>
            <groupId> org.threeten </groupId>
            <artifactId>threetenbp</artifactId>
            <version>1.3.5</version>
        </dependency>
</dependencies>

After configuring, click Import Changes to import all required jar files.If you are using Eclipse, you can refer to the Import Method.
Import results:

Mode 2: Manual Download jar package And then unzip the file, import the jar manually, and import several other jar files manually as well.

2. Log in to Ice Blue Cloud account, create folders and upload documents.

3. Create an application to get the App ID and App Key.


After completing the above steps, you can refer to the following code examples for document conversion.
[Example 1] Convert PDF to Word (Docx, Doc supported), Html, XPS, SVG, PS, PCL, PNG

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 Source Document

        //PDF to Word (Docx/Doc support)
        String destFilePath = "output/PDFtoWord.docx";
        String format = "Docx";

        /*//PDF To Html
        String destFilePath = "output/PDFtoHtml.html";
        String format = "Html";*/

        /*//PDF Transfer to PCL
        String destFilePath = "output/PDFtoPCL.pcl";
        String format = "Pcl";*/

        /*//PDF Transfer to SVG
        String destFilePath = "output/PDFtoSVG.svg";
        String format = "Svg";*/

        /*//PDF Convert to PS
        String destFilePath = "output/PDFtoPS.ps";
        String format = "Ps";*/

        /*//PDF Convert to XPS
        String destFilePath = "output/PDFtoXPS.xps";
        String format = "Xps";*/

        /*//PDF Transfer to PNG
        String destFilePath = "output/PDFtoPng.png";
        String format = "Png";*/

        String folder ="input";//The folder where the source document is located
        String storage = null;//Ice Blue Cloud Configured 2G Free Storage Space, set to null
        String password = null;//Source document password (no password can be set to null)

        //Invoke method to convert PDF to specified document format
        pdfConvertApi.convert(name,destFilePath,format,folder,storage,password);
    }
}

[Example 2] Convert XPS to Word (Docx, Doc supported), 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 Source Document

        //XPS to Word (Docx, Doc support)
        String destFilepath = "output/XPStoDocx.docx";//Result Document Path
        String format = "Docx";

        /*//XPS To Html
        String destFilepath = "output/XPStoHtml.html";//Result Document Path
        String format = "Html"; */

        /*//XPS Transfer to SVG
        String destFilepath = "output/XPStoSVG.svg";//Result Document Path
        String format = "Svg"; */

        /*//XPS Transfer to PCL
        String destFilepath = "output/XPStoPCL.pcl";//Result Document Path
        String format = "Pcl"; */

        /*//XPS Convert to PS
        String destFilepath = "output/XPStoPS.ps";//Result Document Path
        String format = "Ps";*/

        /*//XPS Transfer to PNG
        String destFilepath = "output/XPStoPNG.png";//Result Document Path
        String format = "Png";*/

        /*//XPS Transfer to PDF
        String destFilepath = "output/XPStoPDF.pdf";//Result Document Path
        String format = "Pdf";*/

        String folder = "input";//The folder where the source document is located
        String storage = null;
        String password = null;

        //Call method to convert XPS file to specified document format
        pdfConvertApi.convert(name, destFilepath, format, folder, storage, password);
    }
}

The results of document conversion are as follows. Note that when converting to SVG format, each page of the source document is saved as a separate SVG file. When the source document is multi-page, a folder is generated by default to place the SVG file in:


(finished)

Posted by fadedline on Tue, 23 Jun 2020 10:26:30 -0700