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

In this tutorial, we will demonstrate how to convert Base64 to PDF in JavaScript using the PDF.co Web API with asynchronous processing. Asynchronous processing is particularly advantageous for handling large files or long-running tasks, as it allows you to submit a request and retrieve results at your convenience. This approach ensures uninterrupted performance and resource optimization.

Below is the image of the source Base64.

Source Base64
Source Base64

Step 1: JavaScript Code Samples

Start by obtaining the code sample:

Step 2: Install Axios Module

Install the axios library for making HTTP requests by typing the following in your terminal:

npm install axios

Step 3: PDF.co API Key

Set your PDF.co API key as the const API_Key value in your code. Obtain your API Key from 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 fileData value for the Destination file parameter.

Upload Base64
Upload Base64 2

Step 5: Base64 Output URL

Next, the PDF.co Upload Base64 API endpoint will generate an output URL 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 index.js in the terminal.

Run Program

Step 8: Base64 to PDF Output

After processing, retrieve the PDF file using the generated output URL from the asynchronous task.

Base64 to PDF Output

Base64 to PDF Output

In this tutorial, you learned how to convert Base64 to PDF in JavaScript using the PDF.co Web API with asynchronous processing. You saw how to upload Base64 content and convert an image to a PDF. Asynchronous processing enables efficient handling of large files, providing a seamless experience for long-running tasks.

For more details on implementing asynchronous processing, refer to the official PDF.co Asynchronous Processing Documentation.

Related Tutorials

See Related Tutorials