Convert Base64 to PDF in JavaScript using PDF.co Web API

In this tutorial, we will show you how to convert Base64 to PDF in JavaScript using PDF.co Web API. Below is the image of the source Base64.

Source Base64
Source Base64

Step 1: JavaScript Code Samples

To begin, you can get a copy of the code samples below:

Step 2: Install Request Module

Next, install the request module for file upload. Type the npm install requests in the terminal.

Step 3: PDF.co API Key

Set your PDF.co API key as the const API_Key value. You can get your API Key in the PDF.co dashboard.

PDF.co API Key

Step 4: Upload Base64

First, we need to upload the sample file to the /v1/file/upload/base64 endpoint. As well as add a filename value for the Destination file parameter.

Upload Base64

Step 5: Base64 Output URL

Next, the PDF.co Upload Base64 API endpoint will generate an output for an image file that we will use to convert to PDF.

Step 6: Convert Image to PDF

Then, we will use the /v1/pdf/convert/from/image endpoint to convert the output link to PDF.

Step 7: Run Program

Finally, run the program by typing the node your_program_name.js in the terminal.

Step 8: Base64 to PDF Output

Here’s the output from converting Base64 to PDF.

Convert Base64 To PDF Output
Convert Base64 To PDF Output

In this tutorial, you learned how to convert Base64 to PDF in JavaScript using PDF.co Web API. You learned how to upload small files as Base64. You also learned how to convert images to PDF using PDF.co Web API.

Video Guide

Related Tutorials

See Related Tutorials