Class DocxToPdfPreflight
- Namespace
- DocToolkit
- Assembly
- DocToolkit.dll
Checks a Word document before converting it, and reports what DocxToPdfConverter may not carry into the PDF.
public static class DocxToPdfPreflight
- Inheritance
-
DocxToPdfPreflight
- Inherited Members
Remarks
Why this exists. The renderer beneath DocxToPdfConverter produces no report of its own, so a conversion that drops something drops it silently and returns a valid PDF. A caller converting documents they did not author has no way to tell which ones need a human to look at them. This answers that, and only that.
It reads the SOURCE and reports presence, never loss. The conversion has not run. A finding means "your document contains this, and this renderer may not represent it" — not "this was removed". The weaker claim is the one that can be honestly made from the input alone, and it is what a caller triaging a batch actually needs.
What it does NOT cover, stated because an empty report otherwise reads as a clean bill of health. Charts, SmartArt, embedded objects and shape effects are all plausible risks and are not detected: authoring a fixture for each is substantial work, and this library does not list a construct it has not watched fail. Detection is also limited to the main document body — a nested table inside a header or footer is not reported, because that case is unmeasured.
It lives in DocToolkit rather than DocToolkit.Docx, beside the converter it is about.
DocxReview is in the Docx project because it reads a document; this is about a
CONVERSION, and the conversions stayed in the core project when the per-concern split ran. The
dependency direction settles it either way - core references Docx, not the reverse, so a
cref to DocxToPdfConverter cannot resolve from there at all.
What is deliberately absent is decided by measurement, because a report that fires on
constructs the renderer handles teaches a caller to ignore it. A text box
(w:txbxContent) renders, and so does a content control (w:sdt) at body level — so
neither is reported there, and a control inside a text box's table is not reported either.
A content control in a TABLE is the exception, and it was found by re-measuring. The same construct that survives at body level loses its text inside a cell, or wrapping a cell or a row. This class excluded content controls outright until 2026-08-27, on the body-level evidence alone — correct for what had been measured, and incomplete.
A footnote is reported only when its BODY reference is missing the run style Word itself
always applies. Neither the footnote's own definition, nor anything about the
separator/continuation-separator boilerplate a FootnotesPart always carries, has any
bearing on whether its text reaches the PDF — measured, not assumed, across four fixture shapes.
A footnote authored by Word, or by AddFootnote(byte[], string, string),
always carries that style on its reference and is never reported; only a reference built by hand
or by another tool without it is. This is why the count reads
body.Descendants<FootnoteReference>() rather than the footnotes part: a footnote
referenced only from a header or footer, or one defined but never referenced at all, is
therefore not counted either — consistent with this class's own "detection is limited to the
main document body" scope above, not a separate carve-out.
Methods
Inspect(byte[])
Reports what docx contains that may not reach a PDF.
public static DocxToPdfPreflightReport Inspect(byte[] docx)
Parameters
docxbyte[]The document that is about to be converted.
Returns
Exceptions
- ArgumentNullException
docxis null.- ArgumentException
docxis empty.- DocumentConversionException
The document could not be opened or read.
InspectAsync(Stream, CancellationToken)
Reports what the .docx in source contains that may not reach a PDF.
source is read to its end and is neither disposed, closed nor
sought.
public static Task<DocxToPdfPreflightReport> InspectAsync(Stream source, CancellationToken ct = default)
Parameters
sourceStreamThe document that is about to be converted.
ctCancellationTokenCancels before the document is read.
Returns
Exceptions
- ArgumentNullException
sourceis null.- ArgumentException
sourceis not readable or held no bytes.- OperationCanceledException
ctwas cancelled.- DocumentConversionException
The document could not be opened or read.