/** * Easy API - Simplified, ergonomic API for common PDF tasks * * This module provides a high-level, user-friendly interface for the most common * PDF operations, with automatic resource management and intuitive method chaining. * * @example * ```typescript * import { EasyPDF } from 'micropdf/easy'; * * // Simple text extraction * const text = await EasyPDF.extractText('document.pdf'); * * // Render to PNG * const buffer = await EasyPDF.renderPage('document.pdf', 0, { dpi: 300 }); * * // Chain operations * await EasyPDF.open('input.pdf') * .getMetadata() * .extractText() * .renderPages({ dpi: 150 }) * .save('output.pdf'); * ``` */ /** * Options for rendering pages */ export interface EasyRenderOptions { /** DPI for rendering (default: 72) */ dpi?: number; /** Width in pixels (alternative to DPI) */ width?: number; /** Height in pixels (alternative to DPI) */ height?: number; /** Colorspace (default: RGB) */ colorspace?: 'gray' | 'rgb' | 'cmyk'; /** Include alpha channel (default: false) */ alpha?: boolean; /** Image format for output (default: 'png') */ format?: 'png' | 'pnm' | 'pam' | 'pbm'; } /** * PDF metadata */ export interface PdfMetadata { title?: string; author?: string; subject?: string; keywords?: string; creator?: string; producer?: string; creationDate?: Date; modDate?: Date; } /** * Page information */ export interface PageInfo { pageNumber: number; width: number; height: number; rotation: number; } /** * Document information */ export interface DocumentInfo { pageCount: number; metadata: PdfMetadata; isEncrypted: boolean; hasXfa: boolean; pages: PageInfo[]; } /** * Text extraction result */ export interface ExtractedText { text: string; pageNumber: number; blocks?: Array<{ text: string; bbox: { x: number; y: number; width: number; height: number; }; }>; } /** * Search result */ export interface SearchResult { text: string; pageNumber: number; bbox: { x: number; y: number; width: number; height: number; }; } /** * EasyPDF - Fluent builder for PDF operations */ export declare class EasyPDF { private doc; private autoClose; private constructor(); /** * Open a PDF document * * @param path - Path to PDF file * @param password - Optional password for encrypted PDFs * @returns EasyPDF instance for chaining * * @example * ```typescript * const pdf = EasyPDF.open('document.pdf'); * ``` */ static open(path: string, password?: string): EasyPDF; /** * Open a PDF from a buffer * * @param buffer - Buffer containing PDF data * @param password - Optional password for encrypted PDFs * @returns EasyPDF instance for chaining * * @example * ```typescript * const buffer = await fs.readFile('document.pdf'); * const pdf = EasyPDF.fromBuffer(buffer); * ``` */ static fromBuffer(buffer: Uint8Array | globalThis.Buffer, password?: string): EasyPDF; /** * Extract text from a PDF file (static helper) * * @param path - Path to PDF file * @param pageNumber - Optional page number (0-indexed), or undefined for all pages * @returns Extracted text * * @example * ```typescript * // Extract all text * const allText = await EasyPDF.extractText('document.pdf'); * * // Extract from specific page * const pageText = await EasyPDF.extractText('document.pdf', 0); * ``` */ static extractText(path: string, pageNumber?: number): Promise; /** * Render a specific page to an image buffer (static helper) * * @param path - Path to PDF file * @param pageNumber - Page number (0-indexed) * @param options - Render options * @returns Image buffer * * @example * ```typescript * const pngBuffer = await EasyPDF.renderPage('document.pdf', 0, { * dpi: 300, * format: 'png' * }); * await fs.writeFile('page.png', pngBuffer); * ``` */ static renderPage(path: string, pageNumber: number, options?: EasyRenderOptions): Promise; /** * Get document information (static helper) * * @param path - Path to PDF file * @returns Document information * * @example * ```typescript * const info = await EasyPDF.getInfo('document.pdf'); * console.log(`Pages: ${info.pageCount}`); * console.log(`Title: ${info.metadata.title}`); * ``` */ static getInfo(path: string): Promise; /** * Search for text in a PDF (static helper) * * @param path - Path to PDF file * @param query - Text to search for * @param pageNumber - Optional page number (0-indexed), or undefined for all pages * @returns Array of search results * * @example * ```typescript * const results = await EasyPDF.search('document.pdf', 'important'); * console.log(`Found ${results.length} occurrences`); * ``` */ static search(path: string, query: string, pageNumber?: number): Promise; /** * Get the number of pages * * @returns Page count */ get pageCount(): number; /** * Check if document is encrypted * * @returns True if encrypted */ get isEncrypted(): boolean; /** * Get document metadata * * @returns Metadata object * * @example * ```typescript * const metadata = pdf.getMetadata(); * console.log(metadata.title); * console.log(metadata.author); * ``` */ getMetadata(): PdfMetadata; /** * Get document information * * @returns Complete document information * * @example * ```typescript * const info = pdf.getInfo(); * console.log(`Document has ${info.pageCount} pages`); * info.pages.forEach((page, i) => { * console.log(`Page ${i}: ${page.width}x${page.height}`); * }); * ``` */ getInfo(): DocumentInfo; /** * Extract text from a specific page * * @param pageNumber - Page number (0-indexed) * @returns Extracted text * * @example * ```typescript * const text = pdf.extractPageText(0); * console.log(text); * ``` */ extractPageText(pageNumber: number): string; /** * Extract text from all pages * * @param separator - Separator between pages (default: '\n\n---\n\n') * @returns Extracted text * * @example * ```typescript * const allText = pdf.extractAllText(); * ``` */ extractAllText(separator?: string): string; /** * Extract structured text with bounding boxes * * @param pageNumber - Page number (0-indexed), or undefined for all pages * @returns Array of extracted text with structure * * @example * ```typescript * const structured = pdf.extractStructuredText(0); * structured.forEach(block => { * console.log(`Text: ${block.text}`); * console.log(`Position: ${block.bbox.x}, ${block.bbox.y}`); * }); * ``` */ extractStructuredText(pageNumber?: number): ExtractedText[]; /** * Search for text in the document * * @param query - Text to search for * @param pageNumber - Optional page number (0-indexed), or undefined for all pages * @returns Array of search results * * @example * ```typescript * const results = pdf.search('important'); * results.forEach(result => { * console.log(`Found on page ${result.pageNumber}: ${result.text}`); * }); * ``` */ search(query: string, pageNumber?: number): SearchResult[]; /** * Render a page to a buffer * * @param pageNumber - Page number (0-indexed) * @param options - Render options * @returns Image buffer * * @example * ```typescript * const pngBuffer = pdf.renderToBuffer(0, { dpi: 300 }); * await fs.writeFile('page.png', pngBuffer); * ``` */ renderToBuffer(pageNumber: number, options?: EasyRenderOptions): Buffer; /** * Render a page to a file * * @param pageNumber - Page number (0-indexed) * @param outputPath - Output file path * @param options - Render options * * @example * ```typescript * await pdf.renderToFile(0, 'page.png', { dpi: 300 }); * ``` */ renderToFile(pageNumber: number, outputPath: string, options?: EasyRenderOptions): Promise; /** * Render all pages * * @param options - Render options * @returns Array of image buffers * * @example * ```typescript * const pages = pdf.renderAll({ dpi: 150 }); * pages.forEach((buffer, i) => { * fs.writeFileSync(`page-${i}.png`, buffer); * }); * ``` */ renderAll(options?: EasyRenderOptions): Buffer[]; /** * Render all pages to files * * @param outputPattern - Output file pattern (use {page} for page number) * @param options - Render options * * @example * ```typescript * await pdf.renderAllToFiles('output/page-{page}.png', { dpi: 150 }); * ``` */ renderAllToFiles(outputPattern: string, options?: EasyRenderOptions): Promise; /** * Disable automatic closing (for manual resource management) * * @returns this for chaining */ keepOpen(): this; /** * Close the document and free resources * * @example * ```typescript * const pdf = EasyPDF.open('document.pdf'); * try { * // Use pdf... * } finally { * pdf.close(); * } * ``` */ close(): void; /** * Use the PDF document within a callback, automatically closing it * * @param callback - Callback function * @returns Result of callback * * @example * ```typescript * const text = await EasyPDF.open('document.pdf').use(pdf => { * return pdf.extractAllText(); * }); * ``` */ use(callback: (pdf: this) => T): T; /** * Use the PDF document within an async callback, automatically closing it * * @param callback - Async callback function * @returns Promise with result of callback * * @example * ```typescript * const info = await EasyPDF.open('document.pdf').useAsync(async pdf => { * return pdf.getInfo(); * }); * ``` */ useAsync(callback: (pdf: this) => Promise): Promise; private ensureOpen; } /** * Namespace for quick utility functions */ export declare namespace PDFUtils { /** * Extract text from a PDF file */ const extractText: typeof EasyPDF.extractText; /** * Render a page to buffer */ const renderPage: typeof EasyPDF.renderPage; /** * Get document information */ const getInfo: typeof EasyPDF.getInfo; /** * Search for text */ const search: typeof EasyPDF.search; } //# sourceMappingURL=easy.d.ts.map