PDF to Image

This guide will show you how to render all the pages in a PDF document to images in JPEG format and saves them in the specified output directory.

You can also render all the pages in a PDF to images using a custom image encoder.

Sample Input

Render PDF Page to PNG

Before you begin

You should get your API key from yourUniCloud account.

If this is your first time using UniPDF SDK, follow this guide to set up a local development environment.

Clone the project repository

In your terminal, clone the examples repository. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unipdf-examples.git

Navigate to the render folder in the unipdf-examples directory.

cd unipdf-examples/render

How it works

Lines 12-22 import the UniPDF packages and other required dependencies.

The init function in lines 24-31 authenticates your request with your UNIDOC_LICENSE_API_KEY.

The main function in lines 33-80 validates your input and renders each page in the input PDF to a PNG file. The PNG files are saved to the specified output directory.

Run the code

Run this command to convert PDF pages to images. This will also get all the required dependencies to run the program.

go run pdf_image_render.go OUTPUT_DIR INPUT.pdf

Sample output

Each page in the input PDF is rendered as an image in the output directory. Rendered PDF Page

Got any Questions?

We're here to help you.