Docly Developers
Knowledge base Clarification Recommended

linkImage makes thumbnails of PDF files

In shortdocly.linkImage works on a PDF the same way it works on an image: the scaled URL returns the first page of the PDF as an image, in the size, scaling mode and format you ask for (webp, jpg or png). Use it for document thumbnails in file lists instead of a generic PDF icon - there is nothing to generate or store.
Applies to ImagesUploaded filesFile lists
  1. What you'll see

    You list uploaded files - brochures, datasheets, reports - and want a preview of each document. The reference pages for linkImage and the image-scaling articles only talk about images, so it is easy to conclude that a PDF needs a generic icon, a separate thumbnail you upload by hand, or a server-side conversion step.

  2. What's actually happening

    Docly's image scaler accepts PDF files. A scaled URL on a PDF - <file-url>/<embedded-id>/<W>x<H>x<M>/<name>.<ext>, built by linkImage - returns the first page rendered as an image. The scaling modes behave as for images (1 fills and crops, 0 fits), and the extension on the display name chooses the format. Measured 2026-11-28 on an uploaded 671 KB brochure: 160x200x1 returned a 160×200 image as WebP (7.8 KB), JPEG (10 KB) and PNG (80 KB). The result is cached per size like any scaled image, and the size policy in #/images.json applies.

    The Docly admin UI already uses the same rendering for PDF tiles in folder lists (see Preview image in folder lists).

  3. What to do

    Link the file like an image, with the row object from getFiles as the first argument:

    #{ for (let f of docly.getFiles("/Documents")) { }#
      <a href="#docly.linkFile(f, f.File)#">
        <img src="#docly.linkImage(f, f.File, 160, 200, 1, f.filename + '.webp')#"
             width="160" height="200" loading="lazy" alt="#docly.htmlAttributeEncode(f.Title)#">
      </a>
    #{ } }#
    • For an Uploaded File document the embedded id is in the field File.
    • Use one fixed thumbnail size and register it in allowedSizes before you switch the size policy to strict.
    • Keep a file-type icon as fallback for files the scaler cannot render (docx, xlsx, zip).
    • On a publication with a site router, check that scaled URLs pass through it (see The site router answers 500 on attachment and scaled-image URLs).

Last reviewed 28 Nov 2026