Convert PDF to JPEG, PNG or GIF Images in Node.js

How to convert PDF to JPEG, PNG or GIF images in Node.js
Convert PDF to JPEG, PNG or GIF Image in Node.js

PDF is considered to be a suitable document format for printing and sharing. However, there might be cases when you need to convert pages in a PDF file to JPEG, PNG or GIF high resolution images. For example, when you want to embed PDF pages on a web page or want to generate the PDF covers. For such cases, this article demonstrates how to convert PDF files to popular image formats. Particularly, you will learn how to convert PDF to JPEG, PNG or GIF imagew in Node.js.

The following topics shall be covered in this article:

PDF to Image Converter Online REST API and Node.js SDK

In this article, we’ll use Node.js SDK of GroupDocs.Conversion Cloud API to convert PDF to JPEG, PNG or GIF Images in Node.js applications. This API allows you to convert your documents to any format you need. It supports the conversion more than 50 types of documents and images such as Word, Excel, PowerPoint, PDF, HTML, JPG, PNG, CAD. It also provides .NET, Java, PHP, Ruby, Android, and Python SDKs as its document conversion family members for the Cloud API.

You can install GroupDocs.Conversion Cloud to your Node.js applications using the following command in the console:

npm install groupdocs-conversion-cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as shown below:

Convert PDF to JPEG format using REST API in Node.js

You can convert PDF to JPEG image file by following the simple steps given below:

  1. Upload the PDF file to the cloud
  2. Convert PDF to JPEG image online free in Node.js
  3. Download the converted JPEG file

Upload the Image

Firstly, upload the PDF file to the Cloud using the following code sample:

As a result, the uploaded PDF file will be available in the files section of your dashboard on the cloud.

Convert PDF to JPEG file Online using Node.js

Please follow the steps mentioned below to convert PDF to JPEG file programmatically:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set the PDF file path
  • Assign “jpeg” to format
  • Provide output file path
  • Create ConvertDocumentRequest
  • Get results by calling the ConvertApi.convertDocument() method

The following code example shows how to convert pdf to jpeg without losing quality using REST API in Node.js:

Download the Converted File

The above code sample will save the converted PDF file on the cloud. You can download it using the following code sample:

Convert PDF to JPEG image using Advanced Options

Please follow the steps mentioned below using pdf to jpeg high quality online converter API with some advanced settings:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set the PDF file path
  • Assign “jpeg” to format
  • Provide output file path
  • Define JpegConvertOptions
  • Set various convert settings such as dpi, imageQuality, height, margins (top, left, right, bottom), etc.
  • Create ConvertDocumentRequest
  • Get results by calling the ConvertApi.convertDocument() method

The following code example shows how to convert pdf to jpeg format online with advanced convert options:

How to Convert PDF to PNG image Online using Node.js

Please follow the steps mentioned below to convert PDF to PNG file programmatically:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set the PDF file path
  • Assign “png” to format
  • Provide output file path
  • Create ConvertDocumentRequest
  • Get results by calling the ConvertApi.convertDocument() method

The following code example shows how to convert pdf to png without losing quality using REST API in Node.js:

How to Convert PDF to GIF file Online using Node.js

Please follow the steps mentioned below to convert PDF to GIF file programmatically:

  • Create an instance of ConvertApi
  • Create ConvertSettings instance
  • Set the PDF file path
  • Assign “gif” to format
  • Provide output file path
  • Create ConvertDocumentRequest
  • Get results by calling the ConvertApi.convertDocument() method

The following code example shows how to convert pdf to gif without losing quality using REST API in Node.js:

Online PDF to Image Converter

How to convert pdf to image file online? Please try the following pdf to jpeg, pdf to png or pdf to gif free online to images converter, which have been developed using the above API.

Conclusion

In this article, you have learned:

  • how to change pdf to jpeg format on the cloud;
  • how to convert pdf to jpeg on windows 10 using advanced options;
  • programmatically upload the pdf file and then download the converted file from the cloud;
  • programmatically convert pdf to png file format on the cloud;
  • how to convert pdf to gif image format on the cloud;

You can learn more about GroupDocs.Conversion Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser.

Ask a question

You can ask your queries about how to convert pdf to image format, via our Free Support Forum

See Also