docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Create a command-line tool that converts web pages to PDF documents with custom formatting options. The tool should accept a URL and produce a PDF file with specified page size, orientation, and margin settings.
URL to PDF Conversion
Customizable PDF Options
Command-Line Interface
--size (default: A4)--landscape (flag for landscape orientation)--margin (format: "top,right,bottom,left" in inches)Provides browser automation and PDF generation capabilities.
File: converter.test.ts
Test: Generate a basic PDF from a simple HTML page in A4 format with default settings
import { generatePDF } from './converter';
import * as fs from 'fs';
test('generates PDF with default A4 format', async () => {
const outputPath = './test-output-a4.pdf';
await generatePDF('https://example.com', outputPath, {});
expect(fs.existsSync(outputPath)).toBe(true);
const stats = fs.statSync(outputPath);
expect(stats.size).toBeGreaterThan(0);
// Cleanup
fs.unlinkSync(outputPath);
});File: converter.test.ts
Test: Generate a PDF in Letter format with landscape orientation
test('generates PDF in landscape Letter format', async () => {
const outputPath = './test-output-letter.pdf';
await generatePDF('https://example.com', outputPath, {
format: 'Letter',
landscape: true
});
expect(fs.existsSync(outputPath)).toBe(true);
// Cleanup
fs.unlinkSync(outputPath);
});File: converter.test.ts
Test: Generate a PDF with custom margins specified
test('generates PDF with custom margins', async () => {
const outputPath = './test-output-margins.pdf';
await generatePDF('https://example.com', outputPath, {
format: 'A4',
margin: {
top: '0.5in',
right: '0.5in',
bottom: '0.5in',
left: '0.5in'
}
});
expect(fs.existsSync(outputPath)).toBe(true);
// Cleanup
fs.unlinkSync(outputPath);
});