Skip to main content

Overview

PDF4LLM’s extraction methods return plain .NET strings — writing them to disk is handled by the standard library. The recommended approach is System.IO.File.WriteAllText(), which is straightforward, cross-platform, and available without additional dependencies.

Saving Markdown

Always pass System.Text.Encoding.UTF8 explicitly when writing text files. The two-argument overload of File.WriteAllText uses the platform default encoding, which can silently corrupt special characters, symbols, and non-Latin scripts on Windows.

Saving JSON

ToJson() returns a JSON string directly — no additional serialisation step is needed:
The returned JSON is compact by default. To write human-readable indented JSON, round-trip it through System.Text.Json:
For large documents where file size matters, skip the indentation step and write the compact string directly.

Saving plain text


Saving per-page chunks

When using LlamaMarkdownReader, save each page as a separate file using the page number from the chunk metadata to name each file:

Saving with a matching filename

To derive the output filename from the input document automatically:
Path.ChangeExtension() swaps the file extension cleanly, keeping the same directory and stem.

Saving to a different directory

To write output to a different folder while keeping the original filename:

Processing multiple files

To extract and save output for an entire folder of PDFs:

Saving images alongside Markdown

When writeImages: true is used, image files are written to disk automatically during extraction. Create the image directory first, then save the Markdown file alongside it:
Image paths in the Markdown output are relative to wherever the .md file is opened from. Keep your Markdown file and image directory in the same parent folder to ensure image links resolve correctly.

File format summary


Next steps

Extract Markdown

Full walkthrough of ToMarkdown() with all common options.

Extract JSON

Bounding boxes and layout data for custom pipelines.

Extract Text

Plain text extraction and whitespace handling.

Images & Graphics

Controlling image extraction, format, and output path.