Execute #

Executes the specified task on the PDF tools website.

Endpoint #

POST https://trupdf.com/api/v1/execute

Parameters #

  • processId (required): The unique identifier generated in the previous step (start-task).
  • task (required): Specifies the type of task to be performed.
  • pages[0]['filename'] (required): The filename of the PDF file to be processed.
  • pages[0]['server_filename'] (required): The server-side filename of the PDF file to be processed.
  • pages[0]['rotation']: The rotation angle of the PDF page (optional).
  • pages[0]['rotate']: Another parameter for specifying rotation (optional).
  • pages[0]['page']: Specifies the page(s) to be processed. Use 'all' to process all pages.
  • pages[0]['password']: Password for accessing the PDF file (optional).

Example using cURL: #

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -d '{
        "processId": "xYNNUCkqVVWEDsxXOLGZxCbz9ggreeNAOMErSl8wRw1WDsiZbnvECaGV6AwdtUtaYLA2PrI9WuPCGOqdiJcfp2d6d0b9p0gnbePz",
        "task": "merge-pdf",
        "pages": [
          {
            "filename": "example.pdf",
            "server_filename": "merge-pdf.pdf",
            "rotation": 0,
            "rotate": 0,
            "page": "all",
            "password": "file password"
          }
        ]
      }' \
  https://trupdf.com/api/v1/execute

Example using PHP: #

use GuzzleHttp\Client;

$client = new Client();
$token = 'YOUR_API_TOKEN';

$response = $client->get('https://trupdf.com/api/v1/execute', [
    'headers' => [
        'Authorization' => 'Bearer ' . $token,
        'Content-Type' => 'application/json',
    ],
    'json' => [
        'processId' => 'xYNNUCkqVVWEDsxXOLGZxCbz9ggreeNAOMErSl8wRw1WDsiZbnvECaGV6AwdtUtaYLA2PrI9WuPCGOqdiJcfp2d6d0b9p0gnbePz',
        'task' => 'merge-pdf',
        'pages' => [
            [
                'filename' => 'example.pdf',
                'server_filename' => 'merge-pdf.pdf',
                'rotation' => 0,
                'rotate' => 0,
                'page' => 'all',
                'password' => 'file password'
            ]
        ]
    ],
]);

$data = json_decode($response->getBody(), true);

Response #

Upon successful execution of the task, the server returns a JSON response with details of the execution.

Example Response: #

{
    "status": true,
    "start_time": 1708478505,
    "duration": 0.035,
    "processId": "xYNNUCkqVVWEDsxXOLGZxCbz9ggreeNAOMErSl8wRw1WDsiZbnvECaGV6AwdtUtaYLA2PrI9WuPCGOqdiJcfp2d6d0b9p0gnbePz",
    "tool": "merge-pdf",
    "output_filenumber": 1,
    "output_filesize": 265401,
    "download": "http://trupdf.test/api/v1/download/xYNNUCkqVVWEDsxXOLGZxCbz9ggreeNAOMErSl8wRw1WDsiZbnvECaGV6AwdtUtaYLA2PrI9WuPCGOqdiJcfp2d6d0b9p0gnbePz"
}

Error Responses

If any of the required parameters (processId, task, pages[0]['filename'], pages[0]['server_filename']) are missing or invalid, the server responds with an appropriate error message. If there is an issue with executing the task or any other error occurs, the server responds with an error message indicating the failure.

Notes

Ensure that the processId used for execution matches the one generated in the start-task step. The duration field indicates the duration of the execution process. The download field provides a URL to download the processed file.

This step executes the specified PDF processing task and provides a download link for the processed file.