or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-4/

PDF Thumbnail Generator

Build a thumbnail generator that converts PDF pages to in-memory image buffers for further processing.

Capabilities

Convert PDF page to buffer format

Your task is to implement a function that converts a specific page from a PDF document into an in-memory image buffer. The function should accept a PDF file path and a page number, then return the image data as a Node.js Buffer along with metadata about the image.

The converter should support multiple pages and return buffer data that can be used for in-memory processing such as streaming to clients or programmatic manipulation.

  • Given a PDF file at path ./sample.pdf, converting page 1 returns a Buffer containing image data, dimensions, and page number @test
  • Converting page 2 from the same PDF returns a different Buffer with correct page metadata @test
  • The returned Buffer can be written to a file system and creates a valid image @test

Implementation

@generates

API

/**
 * Converts a specific page from a PDF file to an in-memory image buffer.
 *
 * @param {string} pdfPath - Path to the PDF file
 * @param {number} page - Page number to convert (1-indexed)
 * @returns {Promise<{buffer: Buffer, size: string, page: number}>}
 *          Object containing the image buffer, dimensions as string (e.g., "768x512"), and page number
 */
async function convertPageToBuffer(pdfPath, page) {
  // IMPLEMENTATION HERE
}

module.exports = { convertPageToBuffer };

Dependencies { .dependencies }

pdf2pic { .dependency }

Provides PDF to image conversion with buffer output support.

@satisfied-by