How to Convert Images to PDF using PDF.co Web API
In this tutorial, we will learn how to convert images to PDF using PDF.co Web API.
Step 1: Open the Program
So, first of all, let us dive into the program, or here we are having the Node JS program which is basically having the two PDF or two images and we are converting the PDF.
Step 2: Select Image(s) for Conversion
If we go step by step, first of all, we are defining the authentic keys which will go into the headers of the API call.
Then we are having two image source files. Let us see what is inside this so one image is PNG and one is the JPEG.
So here it’s a PNG file and it’s a JPEG.
Step 3: Combine Images and Generate PDF
So basically we’re trying to combine these two images and generate one PDF. We have provided a destination path and here is the URL of the API. So the URL is like “PDF convert from the image” and we are passing the name of the destination file. Then we are passing the URLs in the comma-separated format. And then we are providing the request info like the host information. Then we are passing the varied path in the path parameter and then we are providing the API key into ex API key headers.
Upon getting the request we will get JSON in the output.
Step 4: Enter Log Output
So, basically, if that all goes well, we will get into the destination file. Otherwise, it will show the log. So here I put the ‘log output’.
Step 5: Execute the Program
Now we’re all set to go. I am firing at the terminal and opening, executing the program. Now we got the output in the URL.
It says it has a two-page count. All goes well. It has a score of 200 and the name is .PDF. And the mark trade is remaining. When we explore the API key, we can see the output.
So these are the two images we sent as input and we got the output in the PDF format. So, it’s that easy to convert from the images to PDF. And if we want to see more into this API, we can actually go into the documentation and explore the different options.
Step 6: Open API Documentation
So I have already opened up this API documentation which is at apidocs.pdf.co. Here is the URL endpoint which we have used https://api.pdf.co/v1/pdf/convert/from/image.
These are different file parameters. If we pass the actual file instead of the URLs, we can also utilize the async option.
Step 7: Check the Output
After the output is done. you can check the job info whether it is completed or not. And in the job output, it will have the actual URL of the file. We can download it and get that result.
Check this PDF.co video tutorial using PDF.co Web API and follow us on YouTube!