In this program, we’re going to see how to make the searchable PDF using PDF.co Web API.
- Declare the Pages to be Processed
- Get the Placeholder URL for the PDF
- Process the Request
- Prepare the URL for the “Make Searchable PDF” API Call
- Asynchronous Option
Let’s dive into the code. We have one PDF file which is basically containing an image or the scan version of the page and we are going to make the searchable image or text.
1. Declare the Pages to be Processed
So first of all, we are having the placeholder for the API Keys which will go into in the header of the request. We have the variable or the source file wearing the variable which represents the pages. So basically we are going to declare the pages that need to be processed.
If the page is protected then we need a password, so the placeholder with a password. PDF.co supports many languages: English, French, Spanish, etc. Our input file is in English format. So we’re going to specify the “ENG” here. We are going to specify the destination file name here.
2. Get the Placeholder URL for the PDF
The program is very simple. We’re creating the client of the weblink object of the web client. We are providing the header keys. We have the physical file and to end the process we will require the URL. So first of all, we get the pre-sign URL. Basically, we get the placeholder URL for the PDF file to which we are going to upload the file. We get the pre-sign URL and we provide the source file.
3. Process the Request
So basically we just provide the file name here and we are going to hit the request. Once we record the response back, we basically use the pre-sign URL and we upload the actual file here. Once it is complete, we’re actually doing the processing to make it searchable. So here we generate the URL to make the searchable PDF. We provide the parameters like the name, password, pages, language, and URL.
Once we get the response, we convert it to JSON. We’re using Newton’s opt underneath and if all goes well, we are grabbing the resulting URL and basically downloading the file. After the replacement of the key is completed. We set up the breakpoint here and start the program.
4. Prepare the URL for the “Make Searchable PDF” API Call
As we generated the URL to get the pre-sign URL, we provide the file name here. We get the response. We get the pre-sign URL to which we are going to upload the file. Also, we got different objects that we’re not going to use here. After the success, we get the URL. And we put the file here.
When support has been completed, we are going to make the URL for the make searchable PDF API call. So we provided different parameters like the name of the output file, the password, etc. We keep it blank because we want to process all the pages. We provide English as the language in the URL. We provide the appropriate pre-sign URL.
5. Asynchronous Option
Here’s an asynchronous option. So, there are different versions that we can also process in the asynchronous mode. So if the file is huge, we don’t want to wait for the response while it executes. So, let’s see the output here. PDF is displaying the page count. So it has a total of one page. We download the file and wait in the console until it’s completed.
This is the result. If I want to select the file, I can select it. I can copy it, I can paste it. So, Basically, you can see that the layout is the same but the file is now searchable, and basically it an unscanned version of it. If you want to go more learn more about these API, then you can go into the documentation.
Check this PDF.co video tutorial using PDF.co Web API and follow us on YouTube!
PDF.co video tutorial
PDF.co REST Web API tutorials
- Introduction to PDF.co Web API
- How to Convert Images to PDF
- How to Convert PDF to Image
- How to Find PDF Information
- How to Make PDF Searchable
- How to Merge PDF using API
- How to Split PDF into Pages
- How to Search PDF for Text
- Add Image to Existing PDF
- Add Text to Existing PDF
- How to Convert PDF to Text
- How to Convert PDF to JSON
- How to Convert PDF to XML
- How to Convert PDF to HTML
- How to Generate BarCodes
- How to Read BarCodes