From 899be701db6a97805d62c3809de3a35e2869cd73 Mon Sep 17 00:00:00 2001 From: Tomas Rutkauskas Date: Mon, 9 Nov 2026 10:36:32 +0200 Subject: [PATCH] examples: PDF thumbnail in one pdf -> jpg call; fix the README pdf-to-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 --- README.md | 7 ++++--- examples/thumbnail/main.go | 10 ++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 450b5df..950ccac 100644 --- a/README.md +++ b/README.md @@ -78,10 +78,11 @@ All conversion parameters and explanations can be found [here](https://www.conve ```go jpgRes := convertapi.ConvDef("pdf", "jpg", - param.NewResult("file", extractRes, nil), - param.NewBool("scaleimage", true), - param.NewBool("scaleproportions", true), + param.NewPath("file", "test.pdf", nil), + param.NewString("pagerange", "1"), + param.NewInt("imagewidth", 300), param.NewInt("imageheight", 300), + param.NewBool("fittosize", true), ) ``` diff --git a/examples/thumbnail/main.go b/examples/thumbnail/main.go index 15da9d7..2af4a4e 100644 --- a/examples/thumbnail/main.go +++ b/examples/thumbnail/main.go @@ -12,15 +12,9 @@ func main() { config.Default = config.NewDefault(os.Getenv("API_TOKEN")) // Get your token at https://www.convertapi.com/a/authentication fmt.Println("Creating PDF thumbnail") - extractRes := convertapi.ConvDef("pdf", "jpg", + jpgRes := convertapi.ConvDef("pdf", "jpg", param.NewPath("file", "assets/test.pdf", nil), param.NewString("pagerange", "1"), - ) - - jpgRes := convertapi.ConvDef("jpg", "jpg", - param.NewResult("file", extractRes, nil), - param.NewBool("scaleimage", true), - param.NewBool("scaleproportions", true), param.NewInt("imageheight", 300), ) @@ -30,4 +24,4 @@ func main() { fmt.Println(errs) } -} \ No newline at end of file +}