Table of Contents

Class DocumentDiff

Namespace
PDiffy
Assembly
PDiffy.dll

The differences between two documents or two snapshots. PDF and Word documents and their snapshots are matched element by element, so an edited paragraph is one change instead of a removed line and an added one, and an element that moved is reported as moved. Any other text, such as a JSON snapshot, is compared line by line.

public sealed class DocumentDiff
Inheritance
DocumentDiff
Inherited Members

Properties

Changes

Every change, in snapshot order; Describe(int) lists those that can affect accessibility first. A number that differs by no more than Tolerate(PdfTolerance, double) allows isn't a change.

public IReadOnlyList<DocumentChange> Changes { get; }

Property Value

IReadOnlyList<DocumentChange>

IsEmpty

Whether there are no changes: the snapshots match, or differ only within their tolerances.

public bool IsEmpty { get; }

Property Value

bool

Methods

Compare(DocxDocument, DocxDocument, Action<DocxSnapshotOptions>?)

The differences between two Word documents' snapshots, element by element.

public static DocumentDiff Compare(DocxDocument before, DocxDocument after, Action<DocxSnapshotOptions>? configure = null)

Parameters

before DocxDocument

The earlier document, whose content counts as removed when it's missing from the other.

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

Compare(PdfUaDocument, PdfUaDocument, Action<PdfSnapshotOptions>?)

The differences between two PDFs' snapshots, element by element: what was added, removed, moved or changed, and where, such as before and after a library upgrade.

public static DocumentDiff Compare(PdfUaDocument before, PdfUaDocument after, Action<PdfSnapshotOptions>? configure = null)

Parameters

before PdfUaDocument

The earlier PDF, whose content counts as removed when it's missing from the other.

after PdfUaDocument

The later PDF, whose new content counts as added.

configure Action<PdfSnapshotOptions>

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

Returns

DocumentDiff

CompareExport(DocxDocument, PdfUaDocument)

Compares a Word document with a PDF exported from it, by what a screen reader announces in each: the title and language, the text in reading order, heading levels, alt text, tables with their header rows, lists and links. These are the documents' transcripts (ToTranscript() and ToTranscript()). Layout and fonts aren't compared, since the two formats record them differently.

public static DocumentDiff CompareExport(DocxDocument word, PdfUaDocument pdf)

Parameters

word DocxDocument

The Word document, whose content counts as removed when the PDF doesn't announce it.

pdf PdfUaDocument

The PDF exported from it.

Returns

DocumentDiff

CompareFiles(string, string, Action<PdfSnapshotOptions>?, Action<DocxSnapshotOptions>?)

Compares two files the way pdiffy before after does: a PDF or a Word document is read and snapshotted, and any other text, such as a .verified.pdfua.txt file or JSON, is compared as a snapshot already. A Word document and a PDF are compared by their transcripts, as CompareExport(DocxDocument, PdfUaDocument) compares them.

public static DocumentDiff CompareFiles(string beforePath, string afterPath, Action<PdfSnapshotOptions>? configurePdf = null, Action<DocxSnapshotOptions>? configureDocx = null)

Parameters

beforePath string

The earlier file.

afterPath string

The later file.

configurePdf Action<PdfSnapshotOptions>

What to leave out or scrub from a PDF.

configureDocx Action<DocxSnapshotOptions>

What to leave out or scrub from a Word document.

Returns

DocumentDiff

Remarks

A PDF and a Word document are recognized by their contents, whatever their extensions, so a .docm or .dotx file is read as a Word document. A file that isn't a PDF, a Word document or text, such as an image, throws InvalidDataException.

CompareSnapshots(string, string)

Compares two snapshot texts, such as a verified file's contents and a received one's. PDF and Word snapshots are matched element by element; any other text, such as JSON, line by line. To compare files, use CompareFiles(string, string, Action<PdfSnapshotOptions>?, Action<DocxSnapshotOptions>?).

public static DocumentDiff CompareSnapshots(string before, string after)

Parameters

before string

The earlier snapshot text.

after string

The later snapshot text.

Returns

DocumentDiff

Describe(int)

A summary for a test failure: counts by kind and by section, then up to maxChanges changes, those that can affect accessibility first. Layout lines one after another that moved the same way count as one change, a shift.

public string Describe(int maxChanges = 20)

Parameters

maxChanges int

Returns

string

ToHtml()

A self-contained HTML page with the two snapshots side by side and the changed words highlighted, for reading a failure in a browser or keeping it as a build artifact.

public string ToHtml()

Returns

string

ToJson()

The changes as JSON, for scripts and tools outside .NET: a version number and, for each change, its kind, section, path, page, detail and whether it can affect accessibility. The README describes the shape.

public string ToJson()

Returns

string

ToString()

The same summary as Describe(int), with nothing left out.

public override string ToString()

Returns

string