The ConverterOptions interface provides configuration options to customize the conversion behavior.
interface ConverterOptions {
fileName?: string;
forceExtension?: string;
url?: string;
ocr?: boolean | OCROptions;
doc?: DocOptions;
}
string (optional)Example:
const buffer = readFileSync('./document.pdf');
const markdown = await convertToMarkdown(buffer, {
fileName: 'document.pdf'
});
string (optional)Example:
// Force treat as PDF even if detection fails
const markdown = await convertToMarkdown(buffer, {
forceExtension: '.pdf'
});
Supported Extensions:
.pdf - PDF documents.doc - Binary Word 97-2003 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.txt - Text files.zip - ZIP archives.jpg, .jpeg, .png, .gif - Images.mp3, .wav - Audio filesstring (optional)Example:
// 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=...'
});
boolean | OCROptions (optional)provider: 'handler' with a custom handler(buffer, context) callback when you want full control over OCR (the library performs no HTTP requests in that mode).Example:
const markdown = await convertToMarkdown("scan.pdf", {
ocr: {
provider: "handler",
pdfMode: "auto",
handler: async (buffer, context) => myOcr(buffer, context),
},
});
See Type Definitions for OCROptions, OCRHandler, and OCRHandlerContext.
DocOptions (optional).doc) conversion.The default output contains body text plus non-empty headers and footnotes. For
Buffer or plain-base64 DOC input, set fileName or forceExtension: '.doc' so
the converter can distinguish the shared Compound File container from other
legacy Office formats.
| Property | Type | Default | Description |
|---|---|---|---|
includeHeaders |
boolean |
true |
Include non-empty headers under ## Document headers. |
includeFootnotes |
boolean |
true |
Include non-empty footnotes under ## Footnotes. |
maxInputBytes |
number |
25 MiB | DOC byte limit; maximum 50 MiB. Applies before configured base64 DOC input is decoded. |
maxOutputChars |
number |
2,000,000 | Markdown character limit; maximum 4,000,000. |
const markdown = await convertToMarkdown(docBase64, {
fileName: 'policy.doc',
doc: {
includeFootnotes: false,
maxInputBytes: 10 * 1024 * 1024,
},
});
See Error Handling for controlled DOC conversion errors.
You can combine multiple options:
const markdown = await convertToMarkdown(buffer, {
fileName: 'document.pdf',
forceExtension: '.pdf',
});
When working with buffers without extension information:
const buffer = getSomeBuffer();
const markdown = await convertToMarkdown(buffer, {
fileName: 'unknown-file.pdf' // Helps detect it's a PDF
});
For web-scraped content:
const htmlContent = await fetchWebPage(url);
const markdown = await convertToMarkdown(htmlContent, {
url: url // Enables special handling for known sites
});
When no options are provided: