or run

npx @tessl/cli init
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

PDF Batch Converter

A utility that converts multiple PDF pages to images asynchronously using promise-based operations.

Problem Description

Build a module that converts specified pages from a PDF document to image format. The module should handle multiple pages concurrently and provide error handling for invalid inputs.

Requirements

Your module should accept a PDF file path and an array of page numbers, then convert all requested pages asynchronously. The function must handle multiple pages concurrently and return results for all pages (including both successes and failures).

Input

  • pdfPath (string): Path to the PDF file
  • pages (array of numbers): Page numbers to convert, 1-indexed (first page is 1)
  • options (object, optional): Configuration for the conversion
    • format (string): Output image format, defaults to 'png'
    • savePath (string): Directory to save images, defaults to './output'

Output

Returns a Promise that resolves to an array of result objects, one for each requested page. Each result contains:

  • page (number): The page number that was attempted
  • success (boolean): Whether the conversion succeeded
  • path (string): Path to the saved image file (only if successful)
  • error (string): Error message describing what went wrong (only if failed)

Capabilities

Concurrent page conversion

  • Converting pages [1, 2] from a valid PDF returns success for both pages @test
  • Converting pages [1, 5, 10] from a valid PDF processes all three pages concurrently @test

Error handling with promises

  • Requesting an invalid page number (0) returns an error result for that page @test
  • Requesting pages from a non-existent PDF file returns error results for all pages @test

Implementation

@generates

API

/**
 * Converts specified pages from a PDF to images asynchronously.
 *
 * @param {string} pdfPath - Path to the PDF file
 * @param {number[]} pages - Array of page numbers to convert (1-indexed)
 * @param {Object} options - Configuration options
 * @param {string} options.format - Output format (default: 'png')
 * @param {string} options.savePath - Save directory (default: './output')
 * @returns {Promise<Array<{page: number, success: boolean, path?: string, error?: string}>>}
 */
async function convertPages(pdfPath, pages, options = {}) {
  // Implementation here
}

module.exports = { convertPages };

Dependencies { .dependencies }

pdf2pic { .dependency }

Provides PDF to image conversion capabilities.

@satisfied-by