DEV Community

Shahzad Ashraf
Shahzad Ashraf

Posted on

Effortlessly Render PPTX to PDF in Java with REST API

Creating document viewing or conversion features in Java applications can often lead to unwanted complications, such as managing dependencies and ensuring compatibility across various file formats. With the GroupDocs.Viewer Cloud Java SDK, converting PPTX files to PDF is quick, accurate, and powered by the cloud. This SDK allows developers to convert PowerPoint presentations into fully formatted, portable PDFs with a single API call, eliminating the need for local installations or third-party applications.

The GroupDocs.Viewer Cloud SDK, along with its Java REST API, simplifies the rendering of presentations by handling files in the cloud. It preserves design fidelity, embedded media, and formatting consistency, guaranteeing that the resulting PDF closely resembles the original PowerPoint presentation. Developers can easily integrate the SDK into their Java applications to automate tasks such as report generation, document sharing, or archiving presentations with only a few lines of code.

By utilizing the GroupDocs.Viewer Cloud SDK for Java, you can greatly minimize manual work and enhance productivity. The RESTful architecture provides scalability, security, and compatibility across different environments. This is a dependable option for teams aiming to improve their document management processes or expand their Java applications with high-quality rendering features.

To access the full guide, please click on this link.

Code example:

package com.groupdocs;
import com.groupdocs.cloud.viewer.api.*;
import com.groupdocs.cloud.viewer.client.*;
import com.groupdocs.cloud.viewer.model.*;
import com.groupdocs.cloud.viewer.model.requests.*;

public class RenderPPTXtoPDF {
    public static void main(String[] args) {
        try {
            // Step 1: Set up API credentials and initialize configuration
            String MyAppKey = "your-app-key";
            String MyAppSecret = "your-app-secret";
            Configuration configuration = new Configuration(MyAppKey, MyAppSecret);

            // Step 2: Initialize View API for rendering
            ViewApi viewApi = new ViewApi(configuration);

            // Step 3: Define file info for rendering
            FileInfo fileInfo = new FileInfo();
            // Path to the source file in cloud storage
            fileInfo.setFilePath("SampleFiles\\source.pptx");

            // Step 4: Set up viewing options
            ViewOptions viewOptions = new ViewOptions();
            viewOptions.setFileInfo(fileInfo);
            viewOptions.setViewFormat(ViewOptions.ViewFormatEnum.PDF);

            // Step 5: Set the output PDF options 
            PdfOptions pdfOptions = new PdfOptions();
            pdfOptions.setRenderNotes(true);

            // Step 6: Create and execute the rendering request
            CreateViewRequest viewRequest = new CreateViewRequest(viewOptions);
            ViewResult viewResponse = viewApi.createView(viewRequest);

        } catch (Exception e) {
            System.out.println("Exception encountered: " + e.getMessage());
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)