HTML JPG PDF XML DOCX
  Product Family
PDF

PDF Format Converter via Cloud Java SDK

Export PDF to Microsoft Office® Word, Excel, PowerPoint Presentations, Images, HTML and fixed-layout formats with Aspose.PDF Cloud Java SDK

Get Started

How to Convert PDF to DOCX Using SDK for Java

In order to convert PDF to DOCX, we’ll use Aspose.PDF Cloud Java SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in Java language for various cloud platforms. Open Repository package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console for install it using Maven.

Add Aspose Cloud repository to your application pom.xml

Add Aspose Cloud repository


    <repositories>
        <repository>
            <id>aspose-cloud</id>
            <name>Aspose Cloud Repository</name>
            <url>https://releases.aspose.cloud/java/repo/</url>
        </repository>
    </repositories>

To install the API client library to your local Maven repository, simply execute:

Installation from Github


    mvn clean install

Convert PDF to DOCX via Java SDK

The ConvertPdfToDocx.Convert() method uploads a local PDF file to Aspose Cloud Storage and converts it into a DOCX document. It uses the Aspose.PDF Cloud API, authenticates with AppSecret and AppKey, uploads the input PDF, requests the conversion in “Flow” mode for better text reflow, and saves the resulting DOCX file locally as sample.docx. Finally, it outputs the size of the converted file in bytes.

 

This sample code shows PDF to DOCX Cloud Java SDK Conversion


    package com.aspose.asposecloudpdfusecases.conversions;

    import java.io.File;
    import java.nio.file.Path;
    import java.nio.file.StandardCopyOption;
    import com.aspose.asposecloudpdf.api.PdfApi;
    import com.aspose.asposecloudpdf.model.AsposeResponse;
    import com.aspose.asposecloudpdf.model.DocFormat;

    public class ConvertPdfToDocx {
        public static void Convert() {
            String REMOTE_FOLDER   = "Your_Temp_Pdf_Cloud";
            String LOCAL_FOLDER    = "c:\\Samples";
            String PDF_FILE_NAME  = "sample.pdf";
            String DOCX_OUTPUT = "convert_pdf_output.docx";
        
            try {
                PdfApi pdfApi = new PdfApi(API_KEY, API_SECRET);

                // upload local PDF file to remote storage
                File file = new File(Path.of(LOCAL_FOLDER, PDF_FILE_NAME).toString());
                String srcPath = Path.of(REMOTE_FOLDER, PDF_FILE_NAME).toString();
                pdfApi.uploadFile(srcPath, file, null);
                System.out.println(String.format("Files %s successfully uploaded!", PDF_FILE_NAME));

                // convert PDF To DOCX
                AsposeResponse response = pdfApi.putPdfInStorageToDoc(
                    PDF_FILE_NAME, Path.of(REMOTE_FOLDER, DOCX_OUTPUT).toString(), 
                    null,
                    DocFormat.DOCX.getValue(), 
                    null, null, null,
                    DocRecognitionMode.FLOW.getValue(),
                    null, null
                    REMOTE_FOLDER,
                    null, null);


                if (response.getCode() != 200)
                    System.err.println("Error: unexpected error when converting PDF to DOCX! '" + response.getStatus() + "'");
                else{
                    // download changed PDF file from remote folder...
                    File f = pdfApi.downloadFile(Path.of(REMOTE_FOLDER, DOCX_OUTPUT).toString(), null, null);
                    java.nio.file.Files.copy(Path.of(f.getPath()), Path.of(LOCAL_FOLDER, DOCX_OUTPUT), StandardCopyOption.REPLACE_EXISTING);
                    System.out.println(String.format("File '%s' successfully dowloaded!", Path.of(LOCAL_FOLDER, DOCX_OUTPUT).toString()));
                    System.out.println("Successfully converted PDF document to DOCX ! '" + DOCX_OUTPUT + "'");
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 

Save PDF as XLSX Files via Java SDK

The ConvertPdfToXlsx.Convert() method uploads a local PDF file to Aspose Cloud Storage and converts it into an Excel (XLSX) spreadsheet. Using the Aspose.PDF Cloud API with AppSid and AppSecret, it uploads the PDF, performs the conversion, saves the result locally as sample.xlsx, and then prints the file size of the converted spreadsheet in bytes.

 

This sample code shows PDF to XLSX Cloud Java SDK Conversion


    package com.aspose.asposecloudpdfusecases.conversions;

    import java.io.File;
    import java.nio.file.Path;
    import java.nio.file.StandardCopyOption;
    import com.aspose.asposecloudpdf.api.PdfApi;
    import com.aspose.asposecloudpdf.model.AsposeResponse;

    public class ConvertPdfToXlsx {
        public static void Convert() {
            String REMOTE_FOLDER   = "Your_Temp_Pdf_Cloud";
            String LOCAL_FOLDER    = "c:\\Samples";
            String PDF_FILE_NAME  = "sample.pdf";
            String XLSX_OUTPUT = "convert_pdf_output.xlsx";
        
            try {
                PdfApi pdfApi = new PdfApi("bc529468758ebc938e4c29a1569a6bd2", "5ad16ee3-abef-40da-912e-0d5cf0beaabc");

                // upload local PDF file to remote storage
                File file = new File(Path.of(LOCAL_FOLDER, PDF_FILE_NAME).toString());
                String srcPath = Path.of(REMOTE_FOLDER, PDF_FILE_NAME).toString();
                pdfApi.uploadFile(srcPath, file, null);
                System.out.println(String.format("Files successfully uploaded!"));

                // convert PDF document to XLSX
                AsposeResponse response = pdfApi.putPdfInStorageToXlsx(PDF_FILE_NAME, Path.of(REMOTE_FOLDER, XLSX_OUTPUT).toString(), 
                null, null, null, null, 
                REMOTE_FOLDER,
                null, null);

                if (response.getCode() != 200)
                    System.err.println("Error: unexpected error when converting PDF to XLSX! '" + response.getStatus() + "'");
                else{
                    // download changed PDF file from remote folder...
                    File f = pdfApi.downloadFile(Path.of(REMOTE_FOLDER, XLSX_OUTPUT).toString(), null, null);
                    java.nio.file.Files.copy(Path.of(f.getPath()), Path.of(LOCAL_FOLDER, XLSX_OUTPUT), StandardCopyOption.REPLACE_EXISTING);
                    System.out.println(String.format("File '%s' successfully dowloaded!", Path.of(LOCAL_FOLDER, XLSX_OUTPUT).toString()));
                    System.out.println("Successfully converted PDF document to XLSX ! '" + XLSX_OUTPUT + "'");
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 

Convert PDF to PowerPoint Presentations via Java SDK

The ConvertPdfToPptx.Convert() method uploads a local PDF file to Aspose Cloud Storage and converts it into a PowerPoint (PPTX) presentation. Using the Aspose.PDF Cloud API with AppSid and AppSecret, it uploads the PDF, processes the conversion, saves the output locally as sample.pptx, and prints the size of the generated presentation in bytes.

 

This sample code shows PDF to PowerPoint Cloud Java SDK Conversion


    package com.aspose.asposecloudpdfusecases.conversions;

    import java.io.File;
    import java.nio.file.Path;
    import java.nio.file.StandardCopyOption;
    import com.aspose.asposecloudpdf.api.PdfApi;
    import com.aspose.asposecloudpdf.model.AsposeResponse;

    public class ConvertPdfToPptx {
        public static void Convert() {
            String REMOTE_FOLDER   = "Your_Temp_Pdf_Cloud";
            String LOCAL_FOLDER    = "c:\\Samples";
            String PDF_FILE_NAME  = "sample.pdf";
            String PPTX_OUTPUT = "convert_pdf_output.pptx";
        
            try {
                PdfApi pdfApi = new PdfApi(API_KEY, API_SECRET);

                // upload local PDF file to remote storage
                File file = new File(Path.of(LOCAL_FOLDER, PDF_FILE_NAME).toString());
                String srcPath = Path.of(REMOTE_FOLDER, PDF_FILE_NAME).toString();
                pdfApi.uploadFile(srcPath, file, null);
                System.out.println(String.format("Files successfully uploaded!"));

                // convert PDF to Paowerpoint
                AsposeResponse response = pdfApi.putPdfInStorageToPptx(
                    PDF_FILE_NAME, Path.of(REMOTE_FOLDER, PPTX_OUTPUT).toString(),
                    null, null,
                    REMOTE_FOLDER,
                    null, null);
        
                if (response.getCode() != 200)
                    System.err.println("Error: unexpected error when converting PDF to PPTX! '" + response.getStatus() + "'");
                else{
                    // download changed PDF file from remote folder...
                    File f = pdfApi.downloadFile(Path.of(REMOTE_FOLDER, PPTX_OUTPUT).toString(), null, null);
                    java.nio.file.Files.copy(Path.of(f.getPath()), Path.of(LOCAL_FOLDER, PPTX_OUTPUT), StandardCopyOption.REPLACE_EXISTING);
                    System.out.println(String.format("File '%s' successfully dowloaded!", Path.of(LOCAL_FOLDER, PPTX_OUTPUT).toString()));
                    System.out.println("Successfully converted PDF document to PPTX ! '" + PPTX_OUTPUT + "'");
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 

Portable Document Format PDF to HTML Conversion via Java SDK

The ConvertPdfToHtml.Convert() method uploads a local PDF file to Aspose Cloud Storage and converts it into an HTML format. Using the Aspose.PDF Cloud API with AppSid and AppSecret, it uploads the PDF, performs the conversion, saves the output as a ZIP archive (sample-html.zip) containing the HTML and related resources, and prints the size of the generated file in bytes.

 

This sample code shows PDF to HTML Cloud Java SDK Conversion


    package com.aspose.asposecloudpdfusecases.conversions;

    import java.io.File;
    import java.nio.file.Path;
    import java.nio.file.StandardCopyOption;
    import com.aspose.asposecloudpdf.api.PdfApi;
    import com.aspose.asposecloudpdf.model.AsposeResponse;
    import com.aspose.asposecloudpdf.model.OutputFormat;

    public class ConvertPdfToHtml {
        public static void Convert() {
            String REMOTE_FOLDER   = "Your_Temp_Pdf_Cloud";
            String LOCAL_FOLDER    = "c:\\Samples";

            String PDF_FILE_NAME  = "sample.pdf";
            String HTML_ZIP_FILE_NAME  = "sample_html_output.zip";

            try {
                PdfApi pdfApi = new PdfApi(API_KEY, API_SECRET);

                // upload local PDF file to remote storage
                File file = new File(Path.of(LOCAL_FOLDER, PDF_FILE_NAME).toString());
                String srcPath = Path.of(REMOTE_FOLDER, PDF_FILE_NAME).toString();
                pdfApi.uploadFile(srcPath, file, null);
                System.out.println(String.format("Files successfully uploaded!"));

                // convert PDF To Html (zip)        
                AsposeResponse response = pdfApi.putPdfInStorageToHtml(
                    PDF_FILE_NAME,
                    Path.of(REMOTE_FOLDER, HTML_ZIP_FILE_NAME).toString(),
                    null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                    null, null, null, null, null, null, null, null, null, null, null, null, null, null,
                    REMOTE_FOLDER,
                    null, null, 
                    OutputFormat.ZIP.toString());

                if (response.getCode() != 200)
                    System.err.println("Error: unexpected error when converting PDF To Html! '" + response.getStatus() + "'");
                else{
                    // download changed PDF file from remote folder...
                    File f = ConversionsHelper.pdfApi().downloadFile(Path.of(REMOTE_FOLDER, HTML_ZIP_FILE_NAME).toString(), null, null);
                    java.nio.file.Files.copy(Path.of(f.getPath()), Path.of(LOCAL_FOLDER, HTML_ZIP_FILE_NAME), StandardCopyOption.REPLACE_EXISTING);
                    System.out.println(String.format("File '%s' successfully dowloaded!", Path.of(LOCAL_FOLDER, HTML_ZIP_FILE_NAME).toString()));
                    System.out.println("Successfully converted PDF document to Html! '" + HTML_ZIP_FILE_NAME + "'");
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
 
  • Other Supported Conversions

    You can also convert many other file formats

    BMP TO PDF (Bitmap Image)
    EMF TO PDF (Enhanced Metafile Format)
    EPUB TO PDF (E-book Format)
    GIF TO PDF (Graphical Interchange Format)
    HTML-TO-PDF (Hyper Text Markup Language)
    JPEG TO PDF (JPEG Image)
    MD TO PDF (Markdown)
    PCL TO PDF (Printer Command Language)
    PDF TO BMP (Bitmap Image)
    PDF TO DOCX (Office 2007+ Words Document)
    PDF TO EMF (Enhanced Metafile Format)
    PDF TO EPUB (E-book Format)
    PDF TO GIF (Graphical Interchange Forma)
    PDF TO HTML (Hyper Text Markup Language)
    PDF TO JPEG (JPEG Image)
    PDF TO PDF/A (Portable Document Format/A)
    PDF TO PNG (Portable Network Graphics)
    PDF TO PPTX (Open XML presentation Format)
    PDF TO SVG (Scalable Vector Graphics)
    PDF TO TEX (LaTeX Output Text)
    PDF TO TIFF (Tagged Image Format)
    PDF TO TXT (Text Document)
    PDF TO XLSX (OOXML Excel File)
    PDF TO XPS (XML Paper Specifications)
    PDF TO PPTX (Open XML presentation Format)
    PNG TO PDF (Portable Network Graphics)
    SVG TO PDF (Scalable Vector Graphics)
    TEX TO PDF (LaTeX Output Text)
    TEXT TO PDF (Text Document)
    TIFF TO PDF (Tagged Image Format)
    XPS TO PDF (XML Paper Specifications)