From f8cb610e88aea70e9ead166f014ad41e16f3f5ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joan=20Fabr=C3=A9gat?= Date: Fri, 23 Feb 2024 11:43:49 -0800 Subject: [PATCH] fix --- README.md | 4 ++-- main.mjs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8d1fd43..425d17d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ All requests must by send in POST to the `/convert` endpoint with a `multipart/f * `width`: The width of the output images. Default is 1000. * `background`: The background color of the output images. Default is white. * `quality`: The quality of the output images in percentage. Default is 80. -* `page`: The page to convert starting at 0. Default is 0. +* `page`: The page to convert starting at 1. Default is 1. The server returns `200` if the conversion was successful and the images are available in the response body. In case of error, the server returns a `400` status code with a JSON object containing the error message (format: `{error: string}`). @@ -38,7 +38,7 @@ curl -X POST -F "file=@/path/to/file.pdf" http://localhost:3000/convert -o examp ``` Conversion with custom params (page 2 to JPEG with an orange background): ```bash -curl -X POST -F "file=@/path/to/file.pdf" -F "page=1" -F "format=jpg" -F "background=#F60" http://localhost:3000/convert -o example.jpg +curl -X POST -F "file=@/path/to/file.pdf" -F "page=2" -F "format=jpg" -F "background=#F60" http://localhost:3000/convert -o example.jpg ``` ## Client diff --git a/main.mjs b/main.mjs index 979db6d..7df0858 100644 --- a/main.mjs +++ b/main.mjs @@ -39,7 +39,7 @@ app.post('/convert', upload.single('file'), (req, res) => { + `-flatten ` + `-resize ${+(req.body.width ?? 800)}x${+(req.body.height ?? 600)} ` + `-quality ${+(req.body.quality ?? 80)}% ` - + `pdf:${pdfPath}[${+(req.body.page ?? 0)}] ` + + `pdf:${pdfPath}[${(+(req.body.page ?? 1) - 1)}] ` + `${req.body.format ?? 'webp'}:${imagePath}`); // sending the images as a response