In this tutorial, you’ll learn how to convert EMF to PDF with Java REST API. EMF stands for Enhanced Metafile Format, and it is a type of vector graphic file format used in Microsoft Windows. It is similar to the WMF file format, but is an enhanced version that supports additional features such as color, gradient fills, anti-aliasing and transparency. EMF files can be used for a wide variety of purposes ranging from CAD drawings to digital photos.
But, PDF (Portable Document Format) is a file format developed by Adobe Systems as a universal file format for viewing, printing, and sharing documents. PDF documents are created using Adobe Acrobat, Acrobat Capture, or similar products. The PDF file format preserves document formatting and enables file sharing. PDF files are often used for electronic document distribution as the PDF file retains exactly the layout of the original document. If you’re interested in EMF to PDF Conversion in Java Low Code API then this can be carried out with the help of code given below.
Prerequisite
- Create account and get API credentials
- Download Aspose.Imaging Cloud SDK for Java
- Setup Java project with the above SDK
Steps to Convert EMF 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 EMF file and upload to cloud storage
- Create an object of ConvertImageRequest with input and output file formats
- Call convertImage method to Convert EMF to PDF using REST API
- Save the output PDF file on local disk
Code for EMF 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 = "EMFtoPDF.emf"; | |
String outputFileName = "EMFtoPDF.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 specified above empowers you to convert EMF to PDF with Java REST API. You just have to provide EMF file with the help of the Aspose.Imaging REST API SDK and download output PDF file to save it locally.
This EMF to PDF Conversion could be exploited with any no code or low code apps on any platform.
A related feature might also be helpful to you: How to Convert WMF to PDF with Java REST API