Method Convert
- Namespace
- LMKit.Document.Conversion
- Assembly
- LM-Kit.NET.dll
Convert(string, DocumentToMarkdownOptions, CancellationToken)
Converts the document at inputPath to Markdown.
public DocumentToMarkdownResult Convert(string inputPath, DocumentToMarkdownOptions options = null, CancellationToken cancellation = default)
Parameters
inputPathstringFile-system path to the source document.
optionsDocumentToMarkdownOptionsOptional conversion options; defaults are used when
null.cancellationCancellationTokenCancellation token.
Returns
- DocumentToMarkdownResult
The conversion result, including the aggregated Markdown and per-page diagnostics.
Exceptions
- ArgumentException
Thrown when
inputPathis null or whitespace.- FileNotFoundException
Thrown when
inputPathdoes not exist.
Convert(byte[], string, DocumentToMarkdownOptions, CancellationToken)
Converts in-memory document bytes to Markdown. The fileName
is used only for MIME detection and logical naming; no file is written.
public DocumentToMarkdownResult Convert(byte[] data, string fileName, DocumentToMarkdownOptions options = null, CancellationToken cancellation = default)
Parameters
databyte[]Raw bytes of the source document.
fileNamestringLogical file name (including extension) used for MIME detection.
optionsDocumentToMarkdownOptionsOptional conversion options; defaults are used when
null.cancellationCancellationTokenCancellation token.
Returns
Examples
using LMKit.Document.Conversion;
byte[] bytes = await httpClient.GetByteArrayAsync("https://example.com/report.pdf");
var converter = new DocumentToMarkdown();
var result = converter.Convert(bytes, "report.pdf");
Convert(Stream, string, DocumentToMarkdownOptions, CancellationToken)
Converts a document read from the specified stream to Markdown.
The stream is consumed in full; caller retains ownership and is responsible for
disposal.
public DocumentToMarkdownResult Convert(Stream stream, string fileName, DocumentToMarkdownOptions options = null, CancellationToken cancellation = default)
Parameters
streamStreamA readable stream positioned at the start of the document.
fileNamestringLogical file name (including extension) used for MIME detection.
optionsDocumentToMarkdownOptionsOptional conversion options; defaults are used when
null.cancellationCancellationTokenCancellation token.
Returns
Examples
using LMKit.Document.Conversion;
using var stream = File.OpenRead("invoice.pdf");
var converter = new DocumentToMarkdown();
var result = converter.Convert(stream, "invoice.pdf");
Convert(ImageBuffer, DocumentToMarkdownOptions, CancellationToken)
Converts a single in-memory image to Markdown. The vision model is used by default; pair TextExtraction with OcrEngine to run traditional OCR instead.
public DocumentToMarkdownResult Convert(ImageBuffer image, DocumentToMarkdownOptions options = null, CancellationToken cancellation = default)
Parameters
imageImageBufferoptionsDocumentToMarkdownOptionscancellationCancellationToken
Returns
Examples
using LMKit.Document.Conversion;
using LMKit.Media.Image;
using var image = new ImageBuffer("screenshot.png");
var converter = new DocumentToMarkdown();
var result = converter.Convert(image);
Convert(Uri, DocumentToMarkdownOptions, CancellationToken)
Downloads the document at the specified uri and converts it to Markdown.
public DocumentToMarkdownResult Convert(Uri uri, DocumentToMarkdownOptions options = null, CancellationToken cancellation = default)
Parameters
uriUrioptionsDocumentToMarkdownOptionscancellationCancellationToken
Returns
Examples
using LMKit.Document.Conversion;
var converter = new DocumentToMarkdown();
var result = await converter.ConvertAsync(new Uri("https://example.com/whitepaper.pdf"));
Convert(Attachment, DocumentToMarkdownOptions, CancellationToken)
Converts the supplied Attachment to Markdown. All other overloads delegate to this method after wrapping their input in an attachment. Use this overload directly when you already hold a pre-built attachment (e.g. carried through a pipeline) and want to avoid re-wrapping it.
public DocumentToMarkdownResult Convert(Attachment attachment, DocumentToMarkdownOptions options = null, CancellationToken cancellation = default)
Parameters
attachmentAttachmentThe source attachment. Must not be
null.optionsDocumentToMarkdownOptionsOptional conversion options; defaults are used when
null.cancellationCancellationTokenCancellation token.
Returns
Examples
using LMKit.Data;
using LMKit.Document.Conversion;
using var attachment = await Attachment.CreateFromFileAsync("report.pdf");
var converter = new DocumentToMarkdown();
var result = await converter.ConvertAsync(attachment);