CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-pdf2pic

A utility for converting pdf to image formats with support for different outputs: directly to file, base64 or buffer.

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-7/

Multi-Format PDF Thumbnail Generator

Build a tool that converts the first page of a PDF document into multiple image formats for different use cases.

Requirements

Create a command-line tool that:

  1. Takes a PDF file path as input
  2. Converts the first page to three different image formats:
    • PNG format for web display
    • JPEG format for email attachments
    • WebP format for modern web applications
  3. Saves all three image files to an output directory with descriptive names

The tool should accept the PDF path as a command-line argument and create the output directory if it doesn't exist.

Implementation

@generates

API

/**
 * Converts the first page of a PDF to multiple image formats
 * @param {string} pdfPath - Path to the PDF file
 * @param {string} outputDir - Directory to save the images
 * @returns {Promise<Object>} Object containing paths to generated images
 */
async function convertToMultipleFormats(pdfPath, outputDir);

Test Cases

  • Given a valid PDF file, it creates PNG, JPEG, and WebP versions of the first page @test
  • The output directory is created if it doesn't exist @test
  • All three image files are saved with correct file extensions @test

Dependencies { .dependencies }

pdf2pic { .dependency }

Provides PDF to image conversion support.

Install with Tessl CLI

npx tessl i tessl/npm-pdf2pic

tile.json