This step by step tutorial shows you how to convert WEBP to PDF with Java REST API. WEBP is an image file format developed by Google. It is an image format that provides lossless and lossy compression for images on the web. It supports both animated and still images and produces relatively small file sizes. The format is mostly used for web graphics, and is supported by most modern web browsers.
On the contrary, PDF (Portable Document Format) is a file format developed by Adobe Systems in 1993 for document exchange. PDF files are created using Adobe Acrobat, Acrobat Capture, or similar products. PDF files are commonly used for publishing documents online because they can preserve the original formatting of the document and make it easy for the user to view and print the document without having to install any special software. PDFs can also be read on almost any device, from computers to smartphones. If you would like WEBP to PDF Conversion in Java Low Code API then the same can be accomplished with the help of the following snippet.
Prerequisite
- Create account and get API credentials
- Download Aspose.Imaging Cloud SDK for Java
- Setup Java project with the above SDK
Steps to Convert WEBP to PDF in Java REST API
- Set Client ID and Client Secret for the API
- Create an object of ImagingAPI class with client credentials
- Specify input and output files
- Read input WEBP file and upload to cloud storage
- Create an object of ConvertImageRequest with input and output file formats
- Call convertImage method to Convert WEBP to PDF using REST API
- Save the output PDF file on local disk
Code for WEBP to PDF Conversion in Java Low Code API
String ClientID = Client.getID(); //replace Client.getID() with your own client ID here | |
String ClientSecret = Client.getSecret(); //replace3 Client.getSecret() with your own client secret here | |
String APIBaseUrl="https://api.aspose.cloud"; | |
String Local_Path = "C:/Temp/"; | |
ImagingApi imagingApiSdk = new ImagingApi(ClientSecret, ClientID, APIBaseUrl); | |
// Input & output file names | |
String inputFileName = "WEBPtoPDF.webp"; | |
String outputFileName = "WEBPtoPDF.pdf"; | |
try { | |
// Upload local image to Cloud Storage | |
File inputFile = new File(Local_Path + inputFileName); | |
FileInputStream inputFileStream = new FileInputStream(inputFile); | |
byte[] inputImageData = IOUtils.toByteArray(inputFileStream); | |
UploadFileRequest uploadFileRequest = new UploadFileRequest(inputFileName, inputImageData, null); | |
FilesUploadResult filesUploadResult = imagingApiSdk.uploadFile(uploadFileRequest); | |
String outputFormat = "pdf"; | |
String remoteFolder = null; // Input file is saved at the root of the storage | |
String remoteStorage = null; // Cloud Storage name | |
ConvertImageRequest convertImageRequest = new ConvertImageRequest(inputFileName, outputFormat, remoteFolder, remoteStorage); | |
byte[] convertedImageData = imagingApiSdk.convertImage(convertImageRequest); | |
// Save exported image to local storage | |
FileOutputStream fileOutputStream = new FileOutputStream(Local_Path + outputFileName); | |
fileOutputStream.write(convertedImageData); | |
fileOutputStream.close(); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} |
The code snippet given on this page lets you convert WEBP to PDF with Java REST API. You merely need to upload WEBP file with the help of the Aspose.Imaging REST API SDK and download output PDF file to save it locally.
This WEBP to PDF Conversion could be consumed with any no code or low code apps on Windows, Linux, or Mac.
A similar feature can be found in the following topic: How to Convert JPG to PDF with Java REST API.