Free Support Forum - aspose.cloud

Convert PDF to JPEG using Aspose.PDF REST API throws conversion error

Hi - I can convert .doc,.txt etc to jpg with cloud api no problem.


However, when i try to convert a single page pdf to jpg I get:

{“Message”:“Format ‘jpg’ is not supported.”}

The pdf’s are put to the cloud correctly, so the problem is the conversion.

Here is the code:

String format = “jpg”;
String storage = “”;
String folder = “”;
String outPath = “”;

storageApi .PutCreate(docToBeConverted, “”, “”, new File(docToBeConverted));

com.aspose.pdf.model.ResponseMessage response =
pdfApi.GetDocumentWithFormat(docToBeConverted, format,storage, folder, outPath);

As a final question, will a multi page pdf be converted to one large jpg is I also just use the above code with a multi-page pdf?

Many Thanks.
Barry

Hi Barry,

Thanks for contacting support.

Please share the resource file, so that we can test the scenario in our environment.

When converting multi-page PDF to JPEG, each page is converted to individual JPEG image.

@barrychoc

As an update, please note the latest version of Aspose.PDF Cloud provides its own API methods for Storage operations. Now you do not need to use Aspose.Storage Cloud API for the purpose. Please find sample code for uploading a PDF file to storage and converting each page to JPEG.

string fileName = "02_pages.pdf";
// Upload source file to aspose cloud storage
pdfApi.UploadFile(fileName, System.IO.File.OpenRead("C:/Temp/02_pages.pdf"));

// Invoke Aspose.PDF Cloud SDK API to get page count from pdf document
var pageCount = pdfApi.GetPages(fileName).Pages.List.Count;
// Convert all pages to separate JPEG images
for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++)
{
    var response = pdfApi.GetPageConvertToJpeg(fileName, pageNumber);
    var fileStream = System.IO.File.Create("C:/Temp/PDFtoJPG_"+pageNumber+".jpg");
    response.CopyTo(fileStream);
    fileStream.Close();
}