DEV Community

Shahzad Ashraf
Shahzad Ashraf

Posted on

Simplify RTF Image Extraction in Java Apps Using the Cloud REST API

Extracting images from RTF files in Java has traditionally been a labor-intensive task that necessitated bespoke parsing strategies and various dependencies. The GroupDocs.Parser Cloud Java SDK simplifies this process, enabling you to accomplish it with ease, reliability, and minimal programming effort. This article illustrates how developers can utilize a Java REST API that streamlines complex document parsing procedures.

By utilizing the Cloud API, developers can eliminate worries over compatibility concerns or the manual extraction of embedded image resources in RTF documents. The Java SDK provides an effective method for connecting your applications to the parsing engine, making it straightforward to extract, manage, and employ images for a wide range of applications—from content repurposing to digital preservation. The entire process consists of just a handful of API calls, which saves valuable time and effort while maintaining accuracy and performance.

For Java app developers, this integration significantly enhances productivity. Rather than spending countless hours developing low-level parsing code, developers can concentrate on creating the features that are most important to their applications. Whether your initiative pertains to enterprise document management, report generation, or content automation, the GroupDocs.Parser Cloud Java SDK offers the flexibility and scalability necessary to keep you ahead of the curve.

If you are eager to improve your Java applications and optimize how you manage RTF documents, check out our detailed step-by-step guide.

Working code example:

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

public class ExtractImagesFromRTF {

    public static void main(String[] args) {

        // Configure your API credentials
        String MyAppKey = "your-app-key";
        String MyAppSid = "your-app-sid";
        Configuration configuration = new Configuration(MyAppKey, MyAppSid);

        // Initialize ParseApi for image extraction
        ParseApi parseApi = new ParseApi(configuration);

        try {
            // Set cloud storage based source RTF file
            FileInfo fileInfo = new FileInfo();
            fileInfo.setFilePath("SampleFiles/source.rtf");

            // Define image extraction options
            ImagesOptions imageOptions = new ImagesOptions();
            imageOptions.setFileInfo(fileInfo);

            // Send and process the image extraction request
            ImagesRequest request = new ImagesRequest(textOptions);
            ImagesResult response = parseApi.images(request);

            // Display the information about the extracted images
            System.out.println("Exracted images:");
            for (Image img : response.getImages()) {

                System.out.println("Image format:" + img.getFileFormat());
                System.out.println("Image path in cloud storage:" + img.getPath());
                System.out.println("Download URL:" + img.getDownloadUrl());
            }

        } catch (Exception e) {

            System.err.println("Exception occurred: " + e.getMessage());
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)