In this example topic, you’ll learn how to convert WMF to PDF with NET REST API. We will develop a WMF to PDF converter with C# Low Code API by adhering to the detailed and simple steps mentioned in the following section. This application can be utilized with any .NET application supported in macOS, Windows, or Linux environments and conversion can be done for free.
Prerequisite
- Create an account and get API credentials to perform WMF to PDF conversion
- Download Aspose.Imaging Cloud SDK for .NET to convert WMF to PDF
- Setup C# .NET project with the above SDK to render WMF as PDF
Steps to Convert WMF to PDF with NET REST API
- Set the Client ID and Client Secret for the API to convert WMF to PDF
- Create an instance of ImagingAPI class with client credentials to perform WMF to PDF conversion
- Specify the source WMF and output PDF file names
- Read the source WMF file and upload it to cloud storage
- Create an instance of the ConvertImageRequest with input WMF file stream and output PDF format
- Call the ConvertImage method to convert WMF to PDF with NET REST API
- Save the rendered PDF file stream on the local disk
The aforementioned renders the file type from WMF to PDF with C# Low Code API. We will start with the configuration of the SDK by initializing the ImagingAPI class object. We will then load the source WMF file using a FileStream and create an instance of the ConvertImageRequest class object that will further be used to perform the conversion to a PDF using the ConvertImage() method.
Code for WMF to PDF Conversion in NET Low Code API
using Aspose.Imaging.Cloud.Sdk.Api; | |
using Aspose.Imaging.Cloud.Sdk.Model.Requests; | |
using Aspose.Imaging.Cloud.Sdk.Model; | |
using System; | |
using System.IO; | |
namespace Kb_Aspose.KB | |
{ | |
public class WmfToPdfConverter | |
{ | |
public void WmfToPdf() | |
{ | |
var clientID = "Client ID"; | |
var clientSecret = "Client Secret"; | |
var apiBaseUrl = "https://api.aspose.cloud"; | |
var localPath = "C:/Words/"; | |
var wmfToPdfImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl); | |
// Source and output file names | |
var inputFileName = "Source.wmf"; | |
var outputFileName = "WMFtoPDF.pdf"; | |
try | |
{ | |
// Upload the local image to Cloud Storage | |
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open); | |
inpuFileStream.Position = 0; | |
var uploadWmfFileRequest = new UploadFileRequest(inputFileName, inpuFileStream, null); | |
wmfToPdfImageApi.UploadFile(uploadWmfFileRequest); | |
var outputFormat = "pdf"; | |
var remoteFolder = null; // Input file is saved at the root of the storage | |
var remoteStorage = null; // Cloud Storage name | |
var convertWmfToPdfRequest = new ConvertImageRequest(inputFileName, outputFormat, | |
remoteFolder, remoteStorage); | |
var pdfDataStream = wmfToPdfImageApi.ConvertImage(convertWmfToPdfRequest); | |
pdfDataStream.Position = 0; | |
using (var fileStream = File.Create(localPath + outputFileName + "." + outputFormat)) | |
{ | |
pdfDataStream.Seek(0, SeekOrigin.Begin); | |
pdfDataStream.CopyTo(fileStream); | |
} | |
} | |
catch (Exception e) | |
{ | |
Console.WriteLine(e.Message); | |
} | |
} | |
} | |
} |
This crisp example code demonstrates how to convert WMF to PDF with C# Cloud API. After fulfilling the pre-requisite requirements, you need to provide a path for the source WMF image on the disk and by utilizing the Aspose.Imaging REST API SDK performs the conversion to PDF. The PDF file stream is returned after the conversion is done and you can then save it locally on the disk.
In this basic article, we have covered to transform WMF to PDF with Cloud API. If you are interested in performing PSD to PDF conversion, refer to the article on how to Convert PSD to PDF with NET REST API.