Skip to content

PDF thumbnail example in one pdf -> jpg call; README pdf-to-jpg snippet compiles and uses real parameters - #21

Merged
tomasr78 merged 1 commit into
mainfrom
fix-pdf-to-jpg-params
Nov 9, 2026
Merged

tomasr78 merged 1 commit into
mainfrom
fix-pdf-to-jpg-params

Conversation

@tomasr78

@tomasr78 tomasr78 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Problem

  • examples/thumbnail/main.go made the thumbnail in two conversions: pdf -> jpg with pagerange 1, then jpg -> jpg with scaleimage, scaleproportions and imageheight 300 to shrink the page. pdf -> jpg can size the image itself, so the second conversion only costs time and a conversion.
  • The README "Additional conversion parameters" snippet did not compile: its file was an undefined extractRes. It also passed scaleimage and scaleproportions to pdf -> jpg. Neither is a pdf-to-jpg parameter (spec), and the API ignores them silently. They exist only on jpg-to-jpg (spec).

Change

  • examples/thumbnail/main.go: one pdf -> jpg call with pagerange 1 and imageheight 300; the width follows the page's aspect ratio. extractRes is gone and the one result is jpgRes. The file now ends with a newline, so gofmt -l no longer lists it.
  • README snippet: converts test.pdf (param.NewPath) and turns page 1 into a JPG that fits inside 300x300, with pagerange, imagewidth, imageheight and fittosize. Without fittosize, pdf-to-jpg applies the width and lets the height grow (300x388 for a US Letter page).

Verification

Docker golang:1.27 (Go 1.27.3), from the repository root, against the production API on 2026-11-09. gofmt -l examples/thumbnail/main.go prints nothing; go vet ./... and go build ./... pass.

$ go run ./examples/thumbnail
Creating PDF thumbnail
Thumbnail saved to:  /tmp/thumbnail.jpg

/tmp/thumbnail.jpg is 231x300 px, 8,858 bytes, from one conversion. The example on main (606cbee) made a 232x300 px, 9,117-byte thumbnail from two conversions.

The README snippet, pasted verbatim into a main that sets the token, then prints jpgRes.Cost() and calls jpgRes.ToPath("/out"), run in a folder holding test.pdf (a copy of assets/test.pdf):

conversion cost: 1 <nil>
saved: /out/test.jpg

test.jpg is byte-identical to the thumbnail above (231x300 px, 8,858 bytes).

Only an example and the README change, not the module, so there is no CHANGELOG entry.

The same README fix for Java is in ConvertAPI/convertapi-library-java#57 and for .NET in ConvertAPI/convertapi-library-dotnet#83. Seen, not changed: nine other examples also lack a final newline (gofmt -l . lists them).

🤖 Generated with Claude Code

…-jpg snippet

examples/thumbnail converted page 1 to JPG, then scaled it with a second
jpg -> jpg conversion. One pdf -> jpg call with pagerange 1 and imageheight
300 makes the thumbnail (231x300 for assets/test.pdf). The result variable
is jpgRes; extractRes is gone. The file now ends with a newline (gofmt).

The README "Additional conversion parameters" snippet used an undefined
extractRes as its file and passed scaleimage and scaleproportions, which
pdf -> jpg does not have. It now converts test.pdf and turns page 1 into a
JPG that fits inside 300x300: pagerange, imagewidth, imageheight and
fittosize.

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 block the PDF thumbnail simplification and README example corrections.

No open issues 🎉

What changed in this PR

Simplifies PDF thumbnail generation and corrects the README’s PDF-to-JPG example to use supported conversion parameters.

Changes:

  • Generates the thumbnail in one PDF-to-JPG conversion, preserving the page’s aspect ratio at 300 pixels high.
  • Replaces the README’s undefined result reference with a file input and parameters that fit page 1 within 300×300 pixels.
File Description
README.md Corrects the input and sizing parameters in the PDF-to-JPG snippet.
examples/​thumbnail/​main.go Removes the second conversion and adds a final newline.

Review effort: Balanced

@tomasr78
tomasr78 merged commit 719594d into main Nov 9, 2026
4 checks passed
@tomasr78
tomasr78 deleted the fix-pdf-to-jpg-params branch November 9, 2026 10:35
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