Skip to content

Instantly share code, notes, and snippets.

Convert PDF to JPEG with C# REST API. For more details: https://kb.aspose.cloud/pdf/net/convert-pdf-to-jpeg-with-net-rest-api/
using System;
using System.IO;
using Aspose.Pdf.Cloud.Sdk.Api;
namespace Aspose.PDF.Cloud.Examples.Kb
{
public class PdfToJpg
{
public static void ConvertPdfToJpg()
{
try
{
PdfApi pdfApi = new PdfApi("apiKey", "apiSid");
string localPath = @"C:\Words\";
string srcFileName = "Sample.pdf";
string outputFile = "PDFtoJpg.jpg";
// Upload source pdf file to the cloud storage
pdfApi.UploadFile(srcFileName, File.Open(localPath + srcFileName, FileMode.Open));
int pageNum = 1;
pdfApi.PutPageConvertToJpeg(srcFileName, pageNum, outputFile, null, null, null, null, null);
// Download the output JPEG file from Cloud Storage
var stream = pdfApi.DownloadFile(outputFile, null, null);
using (var fileStream = File.Create(localPath + outputFile))
{
stream.Seek(0, SeekOrigin.Begin);
stream.CopyTo(fileStream);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine("error:" + ex.Message + "\n" + ex.StackTrace);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment