Table of Contents

Class DocxDocument

Namespace
PDiffy
Assembly
PDiffy.dll

Everything PDiffy reads from a Word document (DOCX), in the order a snapshot prints it.

public sealed record DocxDocument : IEquatable<DocxDocument>
Inheritance
DocxDocument
Implements
Inherited Members

Properties

Body

Paragraphs, tables, content controls, inserted documents, bookmarks between them and content PDiffy can't read, in reading order.

public IReadOnlyList<DocxBlock> Body { get; init; }

Property Value

IReadOnlyList<DocxBlock>

Document

Document-wide details: title, language, compatibility, protection and unreadable parts.

public required DocxDocumentInfo Document { get; init; }

Property Value

DocxDocumentInfo

Footers

Each section's footers, by kind.

public IReadOnlyList<DocxHeaderFooter> Footers { get; init; }

Property Value

IReadOnlyList<DocxHeaderFooter>

Headers

Each section's headers, by kind.

public IReadOnlyList<DocxHeaderFooter> Headers { get; init; }

Property Value

IReadOnlyList<DocxHeaderFooter>

Lists

The lists the document uses, each with the levels it uses.

public IReadOnlyList<DocxList> Lists { get; init; }

Property Value

IReadOnlyList<DocxList>

Notes

Footnotes, endnotes and comments, with what each says.

public IReadOnlyList<DocxNote> Notes { get; init; }

Property Value

IReadOnlyList<DocxNote>

PageSetups

Each section's page size, margins, columns and page numbering, in document order.

public IReadOnlyList<DocxPageSetup> PageSetups { get; init; }

Property Value

IReadOnlyList<DocxPageSetup>

Styles

The styles the document uses, with their properties resolved through the styles they're based on.

public IReadOnlyList<DocxStyle> Styles { get; init; }

Property Value

IReadOnlyList<DocxStyle>

Methods

Check(DocxCheckSet)

Applies the rules in a set, such as Latest, and lists what they find as Check(params DocxCheck[]) does.

public IReadOnlyList<DocxCheckFinding> Check(DocxCheckSet set)

Parameters

set DocxCheckSet

Returns

IReadOnlyList<DocxCheckFinding>

Check(params DocxCheck[])

Applies the checks and lists what they find, grouped by check in the order DocxCheck declares them and then in snapshot order; an empty list means every check passed. With no checks given, applies every check.

public IReadOnlyList<DocxCheckFinding> Check(params DocxCheck[] checks)

Parameters

checks DocxCheck[]

Returns

IReadOnlyList<DocxCheckFinding>

CompareTo(DocxDocument, Action<DocxSnapshotOptions>?)

The differences between this document's snapshot and a later one's, element by element, as Compare(DocxDocument, DocxDocument, Action<DocxSnapshotOptions>?) gives them.

public DocumentDiff CompareTo(DocxDocument after, Action<DocxSnapshotOptions>? configure = null)

Parameters

after DocxDocument

The later document, whose new content counts as added.

configure Action<DocxSnapshotOptions>

What to leave out or scrub from both, as for ToSnapshot(Action<DocxSnapshotOptions>?).

Returns

DocumentDiff

Images()

Every image and other graphic (chart, diagram, shape) in the body, headers, footers and notes, for example, to check alt text.

public IEnumerable<DocxImage> Images()

Returns

IEnumerable<DocxImage>

Load(byte[])

Reads the DOCX in a byte array.

public static DocxDocument Load(byte[] docx)

Parameters

docx byte[]

Returns

DocxDocument

Load(Stream)

Reads the DOCX in a stream from its start, wherever the stream was left, and puts its position back afterward. The stream is left open.

public static DocxDocument Load(Stream docx)

Parameters

docx Stream

Returns

DocxDocument

Remarks

A part that can't be read is listed in UnreadableParts; a file that can't be opened throws. An empty stream, a PDF or a web page throws InvalidDataException saying so.

Load(string)

Reads the DOCX file at a path.

public static DocxDocument Load(string path)

Parameters

path string

Returns

DocxDocument

Paragraphs()

Every paragraph of the body in reading order, including those inside tables, content controls, text boxes and inserted documents.

public IEnumerable<DocxParagraph> Paragraphs()

Returns

IEnumerable<DocxParagraph>

Revisions()

The tracked changes in the body, headers, footers and notes, including inserted documents, for example to check that none shipped: insertions, deletions, moves and formatting changes to text and paragraphs (paragraph marks included) and changes to tables, rows and cells, followed by changes to section settings.

public IEnumerable<DocxRevision> Revisions()

Returns

IEnumerable<DocxRevision>

ToSnapshot(Action<DocxSnapshotOptions>?)

The canonical snapshot text: one paragraph, table cell or style per line, LF endings.

public string ToSnapshot(Action<DocxSnapshotOptions>? configure = null)

Parameters

configure Action<DocxSnapshotOptions>

What to leave out or scrub, e.g. o => o.Ignore(DocxSection.Styles).ScrubDates().

Returns

string

ToTranscript()

The body as the lines a screen reader announces, in reading order, such as "heading level 1: Trail Guide" and "figure: Park logo", in the same shape as ToTranscript(). Pass it to VerifyTextAsync(string, Action<TextSnapshotOptions>?, string, string) for a test that fails when what a screen reader user hears changes.

public string ToTranscript()

Returns

string