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

Source Base64 & PDF Output
Source Base64 & PDF Output

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: API Key

Set your API key as the const API_Key value. You can get the API Key in your dashboard here. 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 name parameter.

Upload Sample File To Base64 Endpoint

Step 5: Base64 Output URL

Next, the 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 Demo

Here’s a quick demo to convert Base64 to PDF.

Convert Base64 To PDF
Convert Base64 To PDF Demo

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

Related Pages:

Related Samples: