extractFileText — Read text from plain text, HTML, and DOCX files.

extractFileText(filename) reads text from a host file and returns a string scalar. This slice supports plain text files with encodings, HTML files through RunMat's extractHTMLText parser, and DOCX files by extracting word/document.xml text.

Syntax

str = extractFileText(filename)
str = extractFileText(filename,Name,Value)

Inputs

NameTypeRequiredDefaultDescription
filenameAnyYesPath to a text, HTML, or DOCX file.
NameValueAnyVariadicName-value options: Encoding and ExtractionMethod in this slice.

Returns

NameTypeDescription
strStringScalarExtracted text.

Errors

IdentifierWhenMessage
RunMat:extractFileText:InvalidInputInputs do not match a supported extractFileText form.extractFileText: invalid input
RunMat:extractFileText:IOErrorThe requested file cannot be read.extractFileText: file read failed
RunMat:extractFileText:UnsupportedFormatThe requested file type or option requires unsupported extraction infrastructure.extractFileText: unsupported file type or option

How extractFileText works

  • filename may be a string scalar, character vector, scalar string array, or 1-by-1 cell containing a text filename.
  • Plain text files are decoded as UTF-8 by default. The Encoding name-value option accepts labels supported by encoding_rs, such as UTF-8, windows-1252, and ISO-8859-1.
  • HTML files with extensions .html, .htm, and .xhtml are decoded as text and passed to extractHTMLText.
  • For HTML files, ExtractionMethod accepts "tree", "article", or "all-text" and follows the existing extractHTMLText compatibility behavior.
  • DOCX files are read as zip archives and text is extracted from word/document.xml, preserving paragraph breaks and basic tabs/line breaks.
  • PDF extraction, website/URL fetching, password-protected documents, PDF page selection, legacy binary DOC, and full Microsoft Word layout fidelity remain tracked by the broader Text Analytics compatibility issue.
  • Unknown file extensions are treated as plain text files.

GPU memory and residency

extractFileText performs host file IO and text parsing and has no provider kernel.

Examples

Read Plain Text

str = extractFileText("notes.txt")

Expected output:

`str` is the file contents as a string scalar.

Read HTML Text

str = extractFileText("page.html", "ExtractionMethod", "all-text")

Expected output:

`str` contains visible text extracted from the HTML file.

Read DOCX Text

str = extractFileText("report.docx")

Expected output:

`str` contains the text runs from the DOCX main document part.

Using extractFileText with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how extractFileText changes the result.

Run a small extractFileText example, explain the result, then change one input and compare the output.

FAQ

Does extractFileText support PDF files?

Not yet. RunMat rejects PDF-specific forms with a clear error and keeps PDF extraction in the broader Text Analytics queue.

Does extractFileText read websites?

Not in this slice. URL extraction requires web fetching behavior and remains tracked.

Does extractFileText execute on the GPU?

No. It performs host file IO and text parsing.

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how extractFileText is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.