# kcode-doc-extraction Agent Integration Reference
`kcode-doc-extraction` is a standalone synchronous Rust 2024 library for local
document-to-text conversion. It uses no remote API.
```rust
use kcode_doc_extraction::{DocumentExtractor, DocumentInput, Result};
fn extract(bytes: Vec<u8>) -> Result<String> {
Ok(DocumentExtractor::default()
.extract(DocumentInput {
file_name: "report.doc".into(),
content_type: "application/msword".into(),
data: bytes,
})?
.text)
}
```
Supported formats are searchable PDF; Word 97-2003 DOC; DOCX; XLSX, XLS, XLSB,
and ODS workbooks; CSV and TSV; plain text and Markdown; JSON; YAML; and XML.
Legacy DOC extraction returns readable body text plus nonempty textboxes in the
parser-returned order. It can preserve a subset of heading styles as Markdown.
It strips field instructions while retaining visible field results and ignores
separate field metadata. It does not preserve Word's visual layout, execute
macros or fields, follow links, or extract embedded OLE objects.
PDFs are not OCRed. DOCX extraction reads `word/document.xml`. Workbooks are
rendered sheet-by-sheet as tabular text. Text-family inputs use lossy UTF-8
decoding.
Format detection prefers the filename extension and falls back to a recognized
media type. In particular, `.doc` and `application/msword` select legacy DOC.
An input named `.doc` is not content-sniffed or silently reclassified as DOCX.
Defaults accept at most 20 MiB and return at most one million Unicode
characters. Newlines, NULs, trailing whitespace, and repeated blank lines are
normalized. The byte limit is applied before parser work and the character
limit after common normalization.
Legacy DOC parser failures and ordinary unwinding panics are converted to
sanitized extraction errors. This baseline does not isolate out-of-memory
conditions, process aborts, or pathological CPU use. Treat strongly hostile
legacy documents in a separately bounded worker process once that stronger
boundary is implemented.
The library contains no multipart parser, HTTP status mapping, filesystem
access, persistence, subprocess invocation, or async runtime. Async servers
should run extraction on a blocking worker. The root `Cargo.toml` version is
canonical and no `Version.txt` is required.