Customer-facing sample apps for MuPDF.NET 4.1 and MuPDF.NET.Office 2.1.0.
Markdown / JSON / text extract (Document.ToMarkdown, ToJson, ToText, ToChunks) and RAG helpers (Utils.LoadAiAsync, Utils.LlamaMarkdownReader, Utils.MarkdownToPdf) are in MuPDF.NET 4.1. Samples PackageReference MuPDF.NET and MuPDF.NET.Office only.
Each feature is a small console project. Packages are referenced via NuGet only.
Every Program.cs uses Main plus one named sample method (for example OpenSave()) with line comments so you can copy that method into your own project. Main only parses args and calls the sample.
Every example writes results under Output/ and compares them to golden files in that project’s Expected/ folder. Look for PASS — / FAIL — / SKIP — in the console. Use run-all.cmd, .\run-all.ps1, or ./run-all.sh to batch-test after NuGet upgrades (they key off those lines; Office samples may AV during process teardown after a successful PASS).
git clone https://github.com/ArtifexSoftware/MuPDF.NET.Examples.git
cd MuPDF.NET.Examples
dotnet restorePackage versions are pinned in Versions.props. NuGet.Config restores from the repo-local LocalNuget/ folder, then nuget.org.
| Path | Role |
|---|---|
Common/ |
Paths, ResultCheck, PDF fingerprints |
Input/ |
Fixtures (committed) |
Output/ |
Generated files (gitignored) |
artifacts/ |
Shared bin/ / obj/ for all samples (gitignored) |
{product}/{NN-Name}/Expected/ |
Golden baselines (committed) |
run-all.cmd / run-all.ps1 / run-all.sh |
Batch PASS/FAIL/SKIP runner |
LocalNuget/ |
Optional local .nupkg drop folder |
LICENSE.md |
Artifex Community License |
SECURITY.md |
Vulnerability reporting |
- .NET 8 SDK (Windows, Linux, or macOS)
- Packages from nuget.org (see
Versions.props) - Optional
MUPDF_OFFICE_KEYfor Office unlock 33-ToJsonLayout/34-ToText/35-ToChunks: optional layout worker needs Python 3.11+ (Ubuntu 22.04:sudo apt install python3.11 python3.11-venv python3.11-full) thendotnet msbuild -t:MuPDFNetSetupLayoutPython— MuPDF.NET README — Layout analysis41-LoadAi: optionalAZURE_OPENAI_*(andAZURE_SEARCH_*) for a live model; default run needs no keys42-Ollama/43-OllamaMagazines: local Ollama (ollama pull mistralandollama pull nomic-embed-text); SKIP when Ollama is not running — seeMuPDF.NET/42-Ollama/README.md
dotnet restore
.\run-all.cmd # Windows
# or: .\run-all.ps1
# or one project:
dotnet run --project MuPDF.NET\01-OpenSave# Linux / macOS (requires pwsh: https://aka.ms/powershell)
dotnet restore
chmod +x ./run-all.sh
./run-all.sh
# or: pwsh ./run-all.ps1
dotnet run --project MuPDF.NET/01-OpenSave.\run-all.cmd --update-expected
# or: .\run-all.ps1 -UpdateExpected
# or:
dotnet run --project MuPDF.NET\01-OpenSave -- --update-expected| Kind | Method |
|---|---|
| Markdown / JSON / text | Exact text (LF-normalized) |
| PNG | SHA-256 |
pageCount + SHA-256 of extracted text (not raw PDF bytes) |
|
| Unlock / page counts | Small *.summary.txt property files |
Each project folder has its own README.md (what it shows, inputs, how to run, APIs).
Naming tip — color vs images
| Want to… | Use |
|---|---|
| Convert page to DeviceCMYK/RGB/Gray | 05-Recolor |
| ICC soft proof, separations, overprint | 19-ColorManagement |
| Place a new image on a page | 09-InsertImage |
| Swap an existing image xref | 17-ReplaceImage |
| Extract embedded images to files | 21-ExtractImages |
| Downsample / recompress images | 20-RewriteImages |
| Compress PDF streams on save | 25-CompressSave |
| Page file attachment annot | 30-FileAnnot (vs 13-EmbeddedFiles) |
| Render many files/pages in parallel | 31-ParallelPixmap (vs sequential 03-RenderPixmap) |
| Product | Projects |
|---|---|
| MuPDF.NET | Open/Save, Pages, Render, Parallel pixmap, Text, Recolor, Story/HTML, Annotations, Widgets, Insert/Replace/Extract images, Outline/Links, Tables, Barcodes, Embedded files, Metadata, TextWriter, Draw shapes, ZUGFeRD, Color management, Rewrite images, GetDrawings, Rotate/Crop, Encrypt, Compress, Watermark, Image→PDF, Image filters, Page ops, File annot, Markdown, JSON layout, Plain text, OCR, Tables→CSV, Llama markdown reader, GetKeyValues, Markdown→PDF, LoadAi (RAG ask/search), Ollama capitals, Ollama magazines, Retrieval chunks |
| MuPDF.NET.Office | Unlock/fonts, Open HWPX/DOCX, Export PDF, Export MD/JSON, Unlock then Document.ToMarkdown |
Edit Versions.props only. Current pins: MuPDF.NET 4.1.1, Office 2.1.0. Restore looks in LocalNuget/, then nuget.org.
See LICENSE.md (Artifex Community License). The NuGet packages these samples use have their own license terms on nuget.org / artifex.com.