Skip to content

Fix the PDF thumbnail example: convert page 1 straight to JPG - #72

Merged
tomasr78 merged 1 commit into
mainfrom
fix-pdf-thumbnail-example
Nov 9, 2026
Merged

tomasr78 merged 1 commit into
mainfrom
fix-pdf-thumbnail-example

Conversation

@tomasr78

@tomasr78 tomasr78 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The example cut page 1 out of the PDF with the extract converter and PageRange 1, then converted that page to JPG. pdf -> extract is now the AI data-extraction converter: it returns JSON and has no PageRange parameter (spec), so the second step gets a JSON file instead of page 1.

The Python example makes the same two calls and fails on production like this:

$ python create_pdf_thumbnail.py        # examples/ on main d653b60, production API, 2026-11-06
Traceback (most recent call last):
  ...
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://v2.convertapi.com/convert/json/to/jpg
  ...
convertapi.exceptions.ApiError: Parameter validation error. Code: 4000. {'SourceFormat, DestinationFormat': ['Unsupported conversion json -> jpg']}

Change

  • One pdf -> jpg call with PageRange 1 makes the thumbnail: one conversion instead of two.
  • ScaleImage and ScaleProportions are dropped. They are not pdf -> jpg parameters (spec) and the API ignores them: with or without them, ImageHeight 300 + ImageWidth 300 returns a 300x388 image for test.pdf (US Letter), byte for byte the same. FitToSize keeps the thumbnail inside 300x300 with its aspect ratio: 231x300.
  • The comment links only https://www.convertapi.com/pdf-to-jpg.

Verification

Run from examples/ against the production API on 2026-11-06, in the php:8.4-cli Docker image (PHP 8.4.27) with TMPDIR=/out:

$ php create_pdf_thumbnail.php
The thumbnail saved to
Array
(
    [0] => /out/test.jpg
)

test.jpg is 231x300 px, 8,858 bytes. php -l examples/create_pdf_thumbnail.php: no syntax errors.

Only the example changes, not the library, so there is no CHANGELOG entry.

The thumbnail examples of the other SDKs are fixed in ConvertAPI/convertapi-library-python#61, ConvertAPI/convertapi-library-ruby#42, ConvertAPI/convertapi-library-java#56, ConvertAPI/convertapi-library-dotnet#82, ConvertAPI/convertapi-library-node#123.

🤖 Generated with Claude Code

pdf -> extract is now the AI data-extraction converter: it returns JSON
and has no PageRange, so the example's second step got a JSON file
instead of page 1 and failed. One pdf -> jpg call with PageRange=1 now
makes the thumbnail, in one conversion instead of two.

ScaleImage and ScaleProportions are not pdf -> jpg parameters and the API
ignored them, so the 300x300 request came back 300x388 for test.pdf.
FitToSize keeps the thumbnail inside 300x300 (231x300).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the PHP thumbnail example update.

No open issues 🎉

What changed in this PR

Fixes the PHP thumbnail example by converting the first PDF page directly to JPG, avoiding the extraction converter’s JSON output.

Changes:

  • Replaces two chained conversions with one PDF-to-JPG call using PageRange 1.
  • Replaces unsupported scaling options with FitToSize to preserve aspect ratio within 300×300 pixels.
  • Updates the example comment and removes the extraction documentation link.
File Description
examples/​create_pdf_thumbnail.php Converts page 1 directly to a proportionally sized JPG thumbnail.

Review effort: Balanced

@tomasr78
tomasr78 merged commit 1d1748e into main Nov 9, 2026
9 checks passed
@tomasr78
tomasr78 deleted the fix-pdf-thumbnail-example branch November 9, 2026 14:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants