Skip to main content

Search OfficeIMO

Enter a topic, API type, or PowerShell command.

Documentation Search all OfficeIMO/

Reader Quick Start

Edit on GitHub

Read Word, PDF, Excel, Markdown, and other documents into Markdown, plain text, or JSON with OfficeIMO.Reader, PSWriteOffice, and the officeimo CLI.

OfficeIMO.Reader turns a document into one normalized result: text, Markdown, pages, headings, tables, and metadata, whatever the source format. Install the adapters for the formats you read; each one brings the shared OfficeIMO.Reader.Core contracts.

dotnet add package OfficeIMO.Reader.Word
dotnet add package OfficeIMO.Reader.Pdf

Read a document as Markdown

Build a reader once with the handlers you need, and reuse it.

C#

using OfficeIMO.Reader;
using OfficeIMO.Reader.Pdf;
using OfficeIMO.Reader.Word;

OfficeDocumentReader reader = new OfficeDocumentReaderBuilder()
    .AddWordHandler()
    .AddPdfHandler()
    .Build();

string markdown = reader.ConvertToMarkdown("Policy.docx");
File.WriteAllText("Policy.md", markdown);

PowerShell

Read-OfficeDocument -Path .\Policy.docx -As Markdown | Set-Content .\Policy.md

CLI

officeimo read Policy.docx --format markdown --output Policy.md

Read the full result as JSON

The JSON result keeps the structure: source details, pages, blocks, tables, chunks, and diagnostics. It can be stored and loaded back.

C#

using OfficeIMO.Reader;
using OfficeIMO.Reader.Pdf;

OfficeDocumentReader reader = new OfficeDocumentReaderBuilder().AddPdfHandler().Build();

OfficeDocumentReadResult document = reader.ReadDocument("Handbook.pdf");
Console.WriteLine($"{document.Kind}: {document.Pages.Count} pages, {document.Chunks.Count} chunks");

string json = document.ToJson(indented: true);
File.WriteAllText("Handbook.json", json);

OfficeDocumentReadResult restored = OfficeDocumentReadResultJson.Deserialize(json);

PowerShell

Read-OfficeDocument -Path .\Handbook.pdf -As Json -Indented | Set-Content .\Handbook.json

CLI

officeimo read Handbook.pdf --format json --output Handbook.json

Read from a stream

Pass a source name with the stream so the reader can pick the handler from its extension:

using OfficeIMO.Reader;
using OfficeIMO.Reader.Word;

OfficeDocumentReader reader = new OfficeDocumentReaderBuilder().AddWordHandler().Build();

using FileStream upload = File.OpenRead("upload.bin");
string markdown = reader.ConvertToMarkdown(upload, "Contract.docx");

Next steps

Limits and reference

Limits: for format coverage, see supported formats and the compatibility matrix.

Reference: OfficeIMO.Reader API · Read-OfficeDocument

API used on this page

Example source