DEV Community

Shahzad Ashraf
Shahzad Ashraf

Posted on

Master PDF-to-PNG Rendering in Java with Cloud REST API

Converting PDF documents to PNG images in Java is now faster and simpler with the GroupDocs.Viewer Cloud Java SDK. Instead of relying on heavy rendering libraries or complex manual methods, you can integrate a cloud-based solution that delivers high-quality image output with minimal effort.

Getting started is straightforward. Install the SDK, set up your cloud credentials, and render PDF pages into PNG format using just a few REST API calls. This approach not only streamlines your workflow but also ensures that your applications are scalable and ready for modern document processing needs. Whether you need to generate previews, build an image-based document viewer, or archive PDFs in a universally viewable format, this SDK has you covered.

Now is the time to take action. Enhance your Java applications with PDF-to-PNG rendering capabilities that improve usability and performance. Integrating the GroupDocs.Viewer Cloud Java SDK means less time dealing with technical barriers and more time building features that your users will love. Start implementing it today and empower your projects with reliable, cloud-powered document rendering.

Check out the complete article by following this link.

Working 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 RenderPDFtoPNG {
    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-sid";
            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.pdf");

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

            // Step 5: Set the output PNG image options 
            ImageOptions imgOptions = new ImageOptions();
            imgOptions.width(1200);
            imgOptions.height(800);
            viewOptions.setRenderOptions(imgOptions);

            // 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)