Convert GIF to PDF with NET REST API

In this simple topic, you’ll explore how to convert GIF to PDF with NET REST API. We will create a GIF 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 amalgamated with any .NET application supported in Windows, Linux, or macOS environments and conversion can be done for free.

Prerequisite

Steps to Convert GIF to PDF with NET REST API

  1. Set the Client ID and Client Secret for the API to convert GIF to PDF
  2. Create an instance of ImagingAPI class with client credentials to perform GIF to PDF conversion
  3. Specify the source GIF and output PDF file names
  4. Read the sample GIF file and upload it to cloud storage
  5. Create an object of the ConvertImageRequest with input file stream and output PDF format
  6. Call the ConvertImage method to convert GIF to PDF with NET REST API
  7. Save the converted PDF file on the local disk with the returned response stream

The above steps transform the file type from GIF to PDF with C# Low Code API. We will start with the initialization of the SDK configuration by creating the ImagingAPI class instance. We will then access the source GIF file using a FileStream from the disk and instantiate a ConvertImageRequest class object that is further used for performing the conversion to a PDF using the ConvertImage() method.

Code for GIF 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 GifToPdfConverter
{
public void GifToPdf()
{
var clientID = "Client ID";
var clientSecret = "Client Secret";
var apiBaseUrl = "https://api.aspose.cloud";
var localPath = "C:/Words/";
var gifToPdfImageApi = new ImagingApi(clientSecret, clientID, apiBaseUrl);
// Source and output file names
var inputFileName = "Source.gif";
var outputFileName = "GIFtoPDF.pdf";
try
{
// Upload the local image to Cloud Storage
var inpuFileStream = File.Open(localPath + '/' + inputFileName, FileMode.Open);
inpuFileStream.Position = 0;
var uploadFileRequest = new UploadFileRequest(inputFileName, inpuFileStream, null);
var filesUploadResult = gifToPdfImageApi.UploadFile(uploadFileRequest);
var outputFormat = "pdf";
var remoteFolder = null; // Input file is saved at the root of the storage
var remoteStorage = null; // Cloud Storage name
var convertGifToPdfRequest = new ConvertImageRequest(inputFileName, outputFormat,
remoteFolder, remoteStorage);
var pdfDataStream = gifToPdfImageApi.ConvertImage(convertGifToPdfRequest);
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 sample code lets you convert GIF to PDF with C# Cloud API. You need to supply a GIF file with the help of the Aspose.Imaging REST API SDK and then after conversion, download the output PDF file stream to save it locally. You may also set the other optional properties while creating the ConvertImageRequest instance that are set to null by default in this sample code.

In this article, we have learned to transform GIF to PDF with Cloud API. If you are interested in performing TIFF to PDF conversion, refer to the article on how to Convert TIFF to PDF with NET REST API.

 English