Skip to content

Converter Options

The ConverterOptions interface provides configuration options to customize the conversion behavior.

Interface Definition

typescript
interface ConverterOptions {
  fileName?: string;
  forceExtension?: string;
  url?: string;
  ocr?: boolean | OCROptions;
}

Options

fileName

  • Type: string (optional)
  • Description: Specifies the file name, which is particularly useful when converting from Buffer or base64 data. Helps with automatic format detection.

Example:

typescript
const buffer = readFileSync('./document.pdf');
const markdown = await convertToMarkdown(buffer, {
  fileName: 'document.pdf'
});

forceExtension

  • Type: string (optional)
  • Description: Forces the converter to treat the input as a specific file type, bypassing automatic detection.

Example:

typescript
// Force treat as PDF even if detection fails
const markdown = await convertToMarkdown(buffer, {
  forceExtension: '.pdf'
});

Supported Extensions:

  • .pdf - PDF documents
  • .docx - Word documents
  • .html, .htm - HTML files
  • .xlsx, .xls - Excel spreadsheets
  • .csv - CSV files
  • .ipynb - Jupyter notebooks
  • .pptx - PowerPoint presentations
  • .xml, .rss, .atom - XML/Feed formats
  • .json - JSON documents
  • .yaml, .yml - YAML documents
  • .epub - EPUB e-books
  • .msg - Outlook email messages
  • .txt - Text files
  • .zip - ZIP archives
  • .jpg, .jpeg, .png, .gif - Images
  • .mp3, .wav - Audio files

url

  • Type: string (optional)
  • Description: Original URL of the content, used for special handling of web content like YouTube videos or Bing search results.

Example:

typescript
// Convert YouTube page
const markdown = await convertToMarkdown(htmlBuffer, {
  url: 'https://www.youtube.com/watch?v=...'
});

// Convert Bing search results
const markdown = await convertToMarkdown(htmlBuffer, {
  url: 'https://www.bing.com/search?q=...'
});

ocr

  • Type: boolean | OCROptions (optional)
  • Description: Enables OCR for images and scanned PDFs. Opt-in — when omitted, no OCR is attempted. Pass true to use the defaults, or an OCROptions object to choose a provider, language, or PDF mode.

Example:

typescript
// Defaults: tesseract provider, 'eng', pdfMode 'auto'
const scanned = await convertToMarkdown('./scan.pdf', { ocr: true });

// Explicit options
const receipt = await convertToMarkdown('./receipt.png', {
  ocr: { provider: 'tesseract', lang: 'eng' }
});

The default tesseract provider requires the tesseract.js peer dependency. See the OCR guide for providers, PDF modes, and vision-model configuration.

Usage Examples

Combining Options

You can combine multiple options:

typescript
const markdown = await convertToMarkdown(buffer, {
  fileName: 'document.pdf',
  forceExtension: '.pdf',
});

Buffer with Format Detection

When working with buffers without extension information:

typescript
const buffer = getSomeBuffer();
const markdown = await convertToMarkdown(buffer, {
  fileName: 'unknown-file.pdf'  // Helps detect it's a PDF
});

Web Content Conversion

For web-scraped content:

typescript
const htmlContent = await fetchWebPage(url);
const markdown = await convertToMarkdown(htmlContent, {
  url: url  // Enables special handling for known sites
});

Default Behavior

When no options are provided:

  • File type is auto-detected from file path extension or buffer content
  • If detection fails, content is treated as plain text
  • No special URL-based processing is applied
  • OCR is not attempted

See Also

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub