Skip to main content
The document. Open or create one, then edit it through body, sections, comments and the other collections. Concepts explains the model.

WordDocument

Unsupported OfficeJS surface kept on the prototype for API-shape compatibility. Import from @reductoai/docx/officejs.

WordDocument properties

WordDocument.create()

Create a blank document from the built-in default template.

WordDocument.from()

Wrap an open session; pass an editor host’s pages as layout to share its IR.

WordDocument.fromBytes()

acceptAllRevisions()

acceptAllRevisionsShown()

addStyle()

assertPageCount()

Throws with an actionable message when layout exceeds maximum.

convertNotes()

Extension (References > Footnotes > Convert): every footnote to an endnote, every endnote to a footnote, or both at once. Both kinds renumber in document order. Returns the notes moved.

declareFont()

Extension: describe a font in the font table, so a host without it picks a like stand-in.

deleteAllComments()

deleteAllCommentsShown()

deleteBookmark()

Remove a bookmark’s markers by name (case-insensitive); its content stays.

dispose()

Extension: frees the layout engine’s copy of this document now; GC frees it otherwise. The document stays usable, and its next layout starts from scratch.

embedFont()

Extension: store one face of a TrueType/OpenType font in the file and set areTrueTypeFontsEmbedded.

getBookmarkRange()

getBookmarkRangeOrNullObject()

getCompatibility()

Extension (VBA Document.Compatibility(Type)): one layout option of w:compat.

getCrossReferenceItems()

office.js Document.getCrossReferenceItems; a caption label (“Figure”) also works, as in VBA.

getFontDeclaration()

Extension: the font table’s description of name, or null when it has none.

getPageCount()

Layout-backed page count for keeping authored documents within a page budget.

getParagraphByUniqueLocalId()

The paragraph whose uniqueLocalId is id, in the body, a header, a footer or a note; throws ItemNotFound. Unlike Word, an id read before a save or a reload still finds it.

getSelection()

The user’s selection at the moment of the call, as a Range. Present only when the host that opened this document supplies one (options.selection, see WordDocument.from); a headless document throws, as Word does with no window. A collapsed caret is an empty range at that point.

getStyles()

getTarget()

Resolve a CLI/page-sketch target id (p:N, c:N:ROW:COL, shape:ID, chart:ID) to a live handle. p:N counts TOP-LEVEL body blocks — the same address space docx read/find print — which is NOT an index into body.paragraphs.items (that collection includes table-cell paragraphs).

insertFileFromBase64()

The file goes into the body, as Body.insertFileFromBase64; resolves to the inserted range.

protect()

Extension: OfficeJS only reads protection. AllowOnlyRevisions locks tracking on.

readPage()

Layout-backed sketch of one 1-based page: header/footer, body text with p:N addresses, images, and empty bands. Use before inserting so you don’t drop content onto a closing plate or split a last page.

readPages()

Omit pages for a one-line index of every page; pass 1-based numbers for full sketches joined by a blank line.

rejectAllRevisions()

rejectAllRevisionsShown()

removeDocumentInformation()

Word’s Document Inspector; see the parity map for what each type scrubs.

removePageNumbers()

Extension (Insert > Page Number > Remove Page Numbers): every PAGE field and page-number block in the headers and footers goes; “Page 3 of 9” goes whole. False when there was none.

removeWatermark()

Extension (Design > Watermark > Remove Watermark).

replaceAll()

Replace every occurrence of find; returns the number of hits.
Literal search over the whole body PLUS every textbox story anchored in it (body.search stays story-scoped, like OfficeJS). Body hits come first, then textbox hits in document order.

set()

setCompatibility()

Extension (VBA Document.Compatibility(Type) = value).

setCompatibilityMode()

Extension (VBA Document.SetCompatibilityMode): “Word2013” and “Current” both write mode 15.

setDefaultFont()

Document-wide default font. Rewrites the theme’s latin typefaces (major and minor) and the styles part’s docDefaults w:rFonts, so Normal, headings, and bullets that inherit the default all follow — no per-run writes needed. Direct run formatting and styles with their own w:rFonts still win, per the usual OOXML precedence, so the report counts what this call did NOT reach: when directRuns is most of runs, the page will not change, and body.font.name = face is the write that does.

setWatermark()

Extension (Design > Watermark > Custom Watermark, Text): a text watermark behind every page, placed in every header (a first-page or even header too). Replaces one already there.

toBytes()

toLayout()

The laid pages of the current edit state, for a painter (@reductoai/viewer, a PDF writer). throughPage lays only up to that page after an edit; later pages and the page count may be stale.

unprotect()

updateFields()

Update field caches and optionally rebuild TOCs; see docs/field-updates.md. Not implemented. These Office.js members throw: activeWindow, areFilePropertiesPasswordEncrypted, areGrammaticalErrorsShown, areMathDefaultsUsed, areNewerFeaturesDisabled, areSpellingErrorsShown, areStylesUpdatedOnOpen, attachedTemplate, autoHyphenation, autoSaveOn, bibliography, characters, coauthoring, codeName, consecutiveHyphensLimit, currentRsid, defaultTabStop, defaultTargetFrame, documentLibraryVersions, doNotEmbedSystemFonts, encryptionProvider, farEastLineBreakLanguage, farEastLineBreakLevel, formattingIsNextLevelShown, formattingIsUserStyleNameShown, fullName, grammaticalErrors, gridDistanceHorizontal, gridDistanceVertical, gridIsOriginFromMargin, gridOriginHorizontal, gridOriginVertical, gridSpaceBetweenHorizontalLines, gridSpaceBetweenVerticalLines, hasPassword, hasVbProject, hyphenateCaps, hyphenationZone, isAutoFormatOverrideOn, isChartDataPointTracked, isCompatible, isFinal, isFontsSubsetSaved, isFormsDataPrinted, isFormsDataSaved, isGrammarChecked, isInAutoSave, isInFormsDesign, isKerningByAlgorithm, isLinguisticDataEmbedded, isMasterDocument, isOptimizedForWord97, isPostScriptPrintedOverText, isQuickStyleSetLocked, isReadOnly, isReadOnlyRecommended, isSnappedToGrid, isSnappedToShapes, isSpellingChecked, isStyleEnforced, isSubdocument, isThemeLocked, isUserControl, isVbaSigned, isWriteReserved, kind, languageDetected, listTemplates, noLineBreakAfter, noLineBreakBefore, onAnnotationClicked, onAnnotationHovered, onAnnotationInserted, onAnnotationPopupAction, onAnnotationRemoved, onContentControlAdded, onParagraphAdded, onParagraphChanged, onParagraphDeleted, openEncoding, originalDocumentTitle, pageSetup, password, passwordEncryptionAlgorithm, passwordEncryptionKeyLength, passwordEncryptionProvider, path, printRevisions, readabilityStatistics, readingLayoutSizeX, readingLayoutSizeY, readingModeIsLayoutFrozen, revisedDocumentTitle, saved, saveEncoding, saveFormat, selection, sentences, settings, spellingErrors, storyRanges, textEncoding, textLineEnding, trackFormatting, webSettings, windows, words, writePassword, xmlAreAdvancedErrorsShown, xmlIsXsltUsedWhenSaving, xmlSaveThroughXslt, activate, addToFavorites, applyQuickStyleSet, applyTheme, autoFormat, canCheckin, checkConsistencyJapanese, checkGrammar, close, closePrintPreview, compare, compareFromBase64, convert, convertAutoHyphens, convertNumbersToText, convertVietnameseDocument, copyStylesFromTemplate, deleteAllInkAnnotations, detectLanguage, fitToPages, freezeLayout, getAnnotationById, getContentControls, getEndnoteBody, getFootnoteBody, importStylesFromJson, lockServerFile, makeCompatibilityDefault, manualHyphenation, post, presentIt, printPreview, redo, reload, reloadAs, removeLockedStyles, removeNumbers, removeTheme, repaginate, resetFormFields, returnToLastReadPosition, runAutoMacro, saveAsQuickStyleSet, select, selectContentControlsByTag, selectContentControlsByTitle, selectLinkedControls, selectNodes, selectSingleNode, selectUnlinkedControls, sendFax, sendMail, setDefaultTableStyle, setPasswordEncryptionOptions, toggleFormsDesign, transformDocument, undo, undoClear, updateStyles, viewCode, viewPropertyBrowser, webPagePreview.

Node additions

WordDocument.open() (node)

Opens like fromBytes, so it starts or joins the document’s billable Session too.

WordDocument.dispose() (node)

Extension: frees the layout engine’s copy of this document now; GC frees it otherwise. The document stays usable, and its next layout starts from scratch.

WordDocument.save() (node)

Writes to path; OfficeJS never writes the source file in place by itself.

WordDocument.toPdf() (node)

Lays out and paints the final view, or the review view asked for; writes path when given.

WordDocument.toPng() (node)

One PNG per laid page (or per pages) of the final or the asked review view, as toPdf lays it.

Browser additions

WordDocument.toPdf() (browser)

Lays out the current edit state and paints it. Faces come through fonts, by default the provider browserLayoutHost was installed with.

WordDocumentOptions

How a WordDocument reaches laid pages and the user’s selection. Omit layout for the platform default. selection is read on every getSelection(), so a host that owns an editor can hand over the live caret without a new handle. Import from @reductoai/docx/node, @reductoai/docx/officejs.