This short tutorial guides on how to convert a PS file to PDF using C# REST API. You will learn to automatically transform PS to PDF using C# Low Code API by using a .NET-based Cloud SDK. It will assist you to perform this task in the Cloud and retrieve the result for saving on the disk.
Prerequisite
- Create an account API credentials to change PS to PDF
- Download Aspose.PDF Cloud SDK for Dotnet for converting PostScript to PDF
- Setup C# project with the above SDK
Steps to Convert PostScript to PDF using C# RESTful Service
- Instantiate the PdfApi class object with client secret and ID for PS to PDF conversion
- Read the PostScript file into a byte array to create a memory stream
- Invoke the PdfApi.UploadFile() method to upload this PostScript data to the Cloud storage
- Call the GetPsInStorageToPdf() method to change the uploaded PS file to a PDF
- Parse the API response and save the PDF created from the PS file
These steps summarize the process to convert PS in PDF using C# .NET-based API. Instantiate the process by loading the PostScript file into a byte array, creating a memory stream from it, and uploading this memory stream to the Cloud storage. Finally, call the GetPsInStorageToPdf() method to change the uploaded PS file to a PDF and save it on the disk.
Code to Convert from PS to PDF using C# REST Interface
using System; | |
using System.IO; | |
using Aspose.Pdf.Cloud.Sdk.Api; | |
using Aspose.Pdf.Cloud.Sdk.Model; | |
using System.Collections.Generic; | |
namespace Aspose.PDF.Cloud.Examples.Kb | |
{ | |
public class PdfTasks // PS to PDF | |
{ | |
public static void ConvertPsToPdf() | |
{ | |
// Initialize API with credentials | |
var pdfService = new PdfApi("Client Secret", "Client ID"); | |
string documentName = "Input.ps"; | |
// Upload the PS file | |
using (var mdFileStream = new MemoryStream(File.ReadAllBytes(documentName))) | |
{ | |
var uploadResult = pdfService.UploadFile(documentName, mdFileStream); | |
} | |
// Change PS to PDF | |
var response = pdfService.GetPsInStorageToPdf(documentName); | |
FileStream fileStream = new FileStream("output.pdf", FileMode.Create, FileAccess.Write); | |
response.CopyTo(fileStream); | |
} | |
} | |
} |
This code has demonstrated the development of a PS file to PDF converter using C# REST API. The PostScript file should be named while adding it to the Cloud storage for later reference. This name is used while calling the GetPsInStorageToPdf() method for referring to the target PS file in the Cloud storage.
This guide has taught us to change the PS format to PDF using C# Low Code API. To convert MHT to PDF, refer to the article on Convert MHT file to PDF using C# REST API.