or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-1/

PDF Thumbnail Generator from Memory

A utility that generates thumbnail images from PDF documents that are already loaded in memory as Buffer objects.

Background

You are building a web API that receives PDF files as upload data. The PDFs need to be converted to thumbnail images without saving them to disk first. The API should support processing PDFs that are received as Buffer objects from file uploads or external API responses.

Requirements

Create a module that converts PDF documents from memory (Buffer objects) into PNG thumbnail images. The module should:

  1. Accept a Buffer containing PDF data as input
  2. Generate a thumbnail image of the first page
  3. Save the thumbnail to a specified output directory
  4. Return metadata about the generated thumbnail including the file path and dimensions

The thumbnail should be 400 pixels wide with aspect ratio preserved, and saved with a density of 150 DPI for good web quality.

Capabilities

Buffer-based PDF conversion

  • Given a Buffer containing valid PDF data, converts the first page to a PNG image at 400px width @test
  • When given a Buffer, saves the output image to the specified directory with correct filename @test

Error handling

  • Throws an error when provided with invalid or corrupted PDF data in the Buffer @test

Implementation

@generates

API

/**
 * Generates a thumbnail image from a PDF Buffer.
 *
 * @param {Buffer} pdfBuffer - The PDF document as a Buffer
 * @param {Object} options - Configuration options
 * @param {string} options.outputDir - Directory where thumbnail will be saved
 * @param {string} options.filename - Base filename for the output (without extension)
 * @returns {Promise<Object>} Object containing { path, width, height, filename }
 */
async function generateThumbnail(pdfBuffer, options) {
  // Implementation here
}

module.exports = { generateThumbnail };

Dependencies { .dependencies }

pdf2pic { .dependency }

Provides PDF to image conversion capabilities with Buffer input support.