The pdfRest Export Form Data API Tool allows users to extract form data from PDF forms fields. This can be particularly useful in scenarios where you need to automate the collection of data from a large number of submitted forms, such as applications, surveys, or registrations. In this tutorial, we will show how to send an API call to the Export Form Data endpoint using PHP to programmatically retrieve form data from PDFs.
'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' // Set the API key in the headers for authentication. ]; $options = [ 'multipart' => [ [ 'name' => 'file', // Specify the field name for the file. 'contents' => Utils::tryFopen('/path/to/file', 'r'), // Open the file specified by the '/path/to/file' for reading. 'filename' => '/path/to/file', // Set the filename for the file to be processed, in this case, '/path/to/file'. 'headers' => [ 'Content-Type' => '' // Set the Content-Type header for the file. ] ], [ 'name' => 'data_format', // Specify the field name for the data file format. 'contents' => 'xml' // Set the value for the data file format (in this case, 'xml'). ], [ 'name' => 'output', // Specify the field name for the output option. 'contents' => 'pdfrest_exported_form_data' // Set the value for the output option (in this case, 'pdfrest_exported_form_data'). ] ] ]; $request = new Request('POST', 'https://api.pdfrest.com/exported-form-data', $headers); // Create a new HTTP POST request with the API endpoint and headers. $res = $client->sendAsync($request, $options)->wait(); // Send the asynchronous request and wait for the response. echo $res->getBody(); // Output the response body, which contains the exported form data content. ?>
Source: GitHub - datalogics/pdf-rest-api-samples
The code starts by loading the necessary classes from the Guzzle HTTP client library, which is a PHP HTTP client that makes it easy to send HTTP requests and trivial to integrate with web services.
use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; use GuzzleHttp\Psr7\Utils;
Next, we set up the headers for the request, including the 'Api-Key' which is used for authentication with the pdfRest API.
$headers = [ 'Api-Key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' ];
The options array is then configured with the 'multipart' content. This includes:
$options = [ // ...multipart array configuration... ];
A new HTTP POST request is created with the specified endpoint and headers, and the request is sent asynchronously. The response is then retrieved and the body of the response, which contains the exported form data, is outputted.
$request = new Request('POST', 'https://api.pdfrest.com/exported-form-data', $headers); $res = $client->sendAsync($request, $options)->wait(); echo $res->getBody();
In this tutorial, we have explored how to use PHP to call the pdfRest Export Form Data API. By sending a properly constructed API call, we can programmatically extract form data from PDFs and use it for further processing or analysis.
Feel free to demo all of the pdfRest API Tools in the API Lab at https://pdfrest.com/apilab/ and refer to the API Reference documentation at https://pdfrest.com/documentation/ for more information.
Note: This is an example of a multipart API call. Code samples using JSON payloads can be found at GitHub - datalogics/pdf-rest-api-samples.
Create your FREE API Key to start processing PDFs in seconds, only possible with pdfRest.