Transforming HTML files into polished PDF documents that are ready for sharing doesn't have to be complicated or lengthy. With the GroupDocs.Viewer Cloud Java SDK, Java developers can effortlessly convert HTML pages into high-quality PDFs using straightforward REST API calls. This cloud-based SDK handles all the challenging aspects — from rendering document layouts to embedding fonts — allowing you to concentrate on developing better applications instead of dealing with file conversion issues.
The SDK is built on the GroupDocs.Viewer Cloud API, a dependable and scalable platform that is designed to manage large-scale rendering tasks. Developers can convert HTML, DOCX, XLSX, and various other formats into viewable or printable outputs like PDFs or image files. With adaptable configuration options, you can easily manage how elements, styles, and images appear in the final PDF, ensuring consistent outcomes every time.
By incorporating the GroupDocs.Viewer Cloud Java SDK into your process, you acquire a robust tool that simplifies intricate rendering tasks, boosts productivity, and enhances document portability. Whether you're generating reports, exporting data from the web, or producing printable versions of web pages, this Cloud API solution offers precision, speed, and reliability — all within your Java environment.
For a comprehensive step-by-step guide, please follow 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 RenderHTMLtoPDF {
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.html");
// 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.setRenderComments(false);
// 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());
}
}
}
Top comments (0)