From b5c41c3e0bcb0c1111a82894489d1bf5a78cb78f Mon Sep 17 00:00:00 2001 From: Tomas Rutkauskas Date: Mon, 9 Nov 2026 15:46:13 +0200 Subject: [PATCH] examples: use the converters the API spec documents The production API spec (https://v2.convertapi.com/info/openapi) has no web -> pdf, any -> zip or docx -> svg converter. - convert_url_to_pdf.php converts the URL with html -> pdf (same Url and FileName parameters) and links the html-to-pdf page. - conversions_chaining.php zips the JPG results with file -> zip. - error_handling.php gets its API error from pdf -> split with a DOCX file (code 4000, the file must be a .pdf) instead of the unsupported docx -> svg conversion (also code 4000). Co-Authored-By: Claude Opus 5.5 --- examples/conversions_chaining.php | 2 +- examples/convert_url_to_pdf.php | 4 ++-- examples/error_handling.php | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/conversions_chaining.php b/examples/conversions_chaining.php index 8bbebf4..a8384dd 100644 --- a/examples/conversions_chaining.php +++ b/examples/conversions_chaining.php @@ -20,7 +20,7 @@ echo "Conversions done. Cost: {$cost}. Total files created: {$count}\n"; -$zipResult = ConvertApi::convert('zip', ['Files' => $jpgResult->getFiles()], 'any'); +$zipResult = ConvertApi::convert('zip', ['Files' => $jpgResult->getFiles()], 'file'); $cost = $zipResult->getConversionCost(); $count = count($zipResult->getFiles()); diff --git a/examples/convert_url_to_pdf.php b/examples/convert_url_to_pdf.php index aa06962..ae86301 100644 --- a/examples/convert_url_to_pdf.php +++ b/examples/convert_url_to_pdf.php @@ -7,9 +7,9 @@ ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); # Example of converting Web Page URL to PDF file -# https://www.convertapi.com/web-to-pdf +# https://www.convertapi.com/html-to-pdf -$fromFormat = 'web'; +$fromFormat = 'html'; $conversionTimeout = 180; $dir = sys_get_temp_dir(); diff --git a/examples/error_handling.php b/examples/error_handling.php index 16dcf06..20a4aea 100644 --- a/examples/error_handling.php +++ b/examples/error_handling.php @@ -7,7 +7,8 @@ ConvertApi::setApiCredentials(getenv('CONVERT_API_SECRET')); try { - $result = ConvertApi::convert('svg', ['File' => 'files/test.docx']); + # test.docx is not a PDF, so the API rejects this PDF split with a validation error + $result = ConvertApi::convert('split', ['File' => 'files/test.docx'], 'pdf'); } catch (\ConvertApi\Error\Api $error) { echo "Got API error code: " . $error->getCode() . "\n"; echo $error->getMessage();