Skip to main content
Version: 9.x

Thumbnails of any document

You have uploads of all kinds: PDFs, Word documents, web pages. You want a small preview image of each one's first page.

Request​

For a PDF, render its first page:

curl \
--request POST http://localhost:3000/forms/pdf/render \
--form files=@report.pdf \
--form pages=1 \
--form dpi=48 \
-o report_1.png

Result​

report_1.png, 298 by 421 pixels: the page at two-thirds of its size in points.

How it works​

  • render draws the pages you pick, and the route answers the image alone: see Render pages as images.
  • dpi sets the size: 72 gives a pixel per point, 48 two-thirds of that.

Variations​

  • A Word document: convert it and render in the same request. The answer is a ZIP with the PDF and report.docx_1.png:
curl \
--request POST http://localhost:3000/forms/libreoffice/convert \
--form files=@report.docx \
--form 'stages=[
{ "op": "render", "pages": "1", "dpi": 48 }
]' \
-o report.zip
  • A web page: take a screenshot with clip, width and height for a fixed size.
  • JPEG, for smaller files: add format: jpeg and a quality.