### CDN Usage Example Source: https://github.com/jsv4/docxodus/blob/main/docs/npm-package.md Demonstrates how to use Docxodus directly from a Content Delivery Network (CDN) without needing to install it via npm, including initialization and document conversion. ```APIDOC ## CDN Usage ### Description Docxodus can be used directly from a CDN, eliminating the need for local installation. ### Usage ```html ``` ### Available Functions via CDN - `initialize()`: Initializes the Docxodus library. - `convertDocxToHtml(docxBytes: Uint8Array, options?: object)`: Converts DOCX bytes to HTML. - `CommentRenderMode`: Enum for specifying comment rendering style. ``` -------------------------------- ### Install docx2html Tool Source: https://github.com/jsv4/docxodus/blob/main/tools/docx2html/README.md Installs the docx2html .NET global tool. This command is required before using the tool. ```bash dotnet tool install -g Docx2Html ``` -------------------------------- ### Install Docxodus Library Source: https://github.com/jsv4/docxodus/blob/main/README.md Install the Docxodus library using the .NET CLI. This command adds the package to your project. ```bash dotnet add package Docxodus ``` -------------------------------- ### Install Redline as a .NET Global Tool Source: https://github.com/jsv4/docxodus/blob/main/tools/redline/README.md Use this command to install the Redline tool globally on your system. Ensure you have the .NET SDK installed. ```bash dotnet tool install --global Redline ``` -------------------------------- ### Install and Use Redline CLI for DOCX Comparison Source: https://context7.com/jsv4/docxodus/llms.txt Compares two DOCX files and writes a redlined DOCX. Installs as a global .NET tool. Custom author names and help are supported. ```bash # Install globally dotnet tool install -g Redline # Basic comparison redline original.docx modified.docx output.docx # With a custom author name redline original.docx modified.docx output.docx --author="Legal Review" # Show help redline --help ``` -------------------------------- ### Install Docx2Html CLI Tool Source: https://github.com/jsv4/docxodus/blob/main/README.md Install the Docx2Html command-line tool globally using the .NET CLI. This tool converts DOCX files to HTML. ```bash # Install globally dotnet tool install -g Docx2Html ``` -------------------------------- ### Install Docxodus npm Package Source: https://github.com/jsv4/docxodus/blob/main/README.md Install the Docxodus npm package for client-side usage in browsers via WebAssembly. ```bash npm install docxodus ``` -------------------------------- ### Setup and Run Playwright Browser Tests Source: https://github.com/jsv4/docxodus/blob/main/README.md Configure and run Playwright tests for the npm/WASM components of Docxodus. This involves installing dependencies, building the project, and executing tests. ```bash # Need to be in npm subdirectory cd npm # Install dependencies (first time only) npm install npx playwright install chromium # Build WASM and TypeScript (required before tests) npm run build # Run all Playwright tests (~62 tests) npm test # Run specific test by name pattern npx playwright test --grep "Document Structure" # Run tests with browser visible npx playwright test --headed # TypeScript type checking npx tsc --noEmit ``` -------------------------------- ### Install Docx2OC CLI Tool Source: https://github.com/jsv4/docxodus/blob/main/CHANGELOG.md Installs the `docx2oc` command-line tool globally using the .NET CLI. This tool facilitates easy conversion of DOCX files to OpenContracts format. ```bash dotnet tool install --global Docx2OC ``` -------------------------------- ### Install Redline CLI Tool Source: https://github.com/jsv4/docxodus/blob/main/README.md Install the Redline command-line tool globally using the .NET CLI. This tool is used for document comparison. ```bash # Install globally dotnet tool install -g Redline ``` -------------------------------- ### Custom ImageHandler Callback Example Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/docx_converter.md Provides a C# example of a custom ImageHandler callback used to process and save images during conversion. It demonstrates saving the image and returning an XElement for an img tag. ```csharp settings.ImageHandler = imageInfo => { // Save image to file var filename = $"image_{Guid.NewGuid()}.png"; imageInfo.SaveImage(filename, SKEncodedImageFormat.Png); return new XElement(Xhtml.img, new XAttribute("src", filename), new XAttribute("alt", imageInfo.AltText ?? ""), imageInfo.ImgStyleAttribute); }; ``` -------------------------------- ### Complete Export Example Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/opencontracts_export.md Demonstrates how to perform a complete export and access content, structural elements, and layout data using the exported object. ```typescript import { exportToOpenContract } from 'docxodus'; const export = await exportToOpenContract(docxFile); // Access complete text console.log(`Total characters: ${export.content.length}`); // Access structural elements const sections = export.labelledText.filter(a => a.annotationLabel === 'SECTION'); const paragraphs = export.labelledText.filter(a => a.annotationLabel === 'PARAGRAPH'); // Access layout data for (const page of export.pawlsFileContent) { console.log(`Page ${page.page.index}: ${page.page.width}x${page.page.height}pt`); console.log(` ${page.tokens.length} tokens`); } ``` -------------------------------- ### HTML Output Structure for Annotations Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/custom_annotations.md Example HTML structure demonstrating how annotations are rendered with labels and metadata. ```APIDOC ## HTML Output Structure This section shows the typical HTML structure generated for custom annotations, including highlights, labels, and metadata attributes. ### Example 1: Annotation with Floating Label ```html Important Clause WHEREAS, the Party of the First Part agrees to... ``` ### Example 2: Multi-paragraph Annotation This example shows how an annotation spanning multiple paragraphs is structured using `annot-start`, `annot-continuation`, and `annot-end` classes. ```html

Important Clause First paragraph of annotated content...

Continuation of annotated content...

Final paragraph of annotated content.

``` ``` -------------------------------- ### WASM Initialization and Setup Source: https://github.com/jsv4/docxodus/blob/main/npm/tests/profiling-harness.html Initializes the WebAssembly module using `dotnet.js`. It measures the time taken for WASM initialization, `dotnet.create()`, and `getAssemblyExports()`, logging the results. ```javascript // Initialize WASM log('Starting WASM initialization...'); const wasmInitStart = performance.now(); import('./_framework/dotnet.js').then(async ({ dotnet }) => { const dotnetCreateStart = performance.now(); const { getAssemblyExports, getConfig } = await dotnet .withDiagnosticTracing(false) .create(); const dotnetCreateTime = performance.now() - dotnetCreateStart; log(` dotnet.create(): ${formatMs(dotnetCreateTime)}`); const getExportsStart = performance.now(); const config = getConfig(); const exports = await getAssemblyExports(config.mainAssemblyName); const getExportsTime = performance.now() - getExportsStart; log(` getAssemblyExports(): ${formatMs(getExportsTime)}`); const wasmInitTime = performance.now() - wasmInitStart; Profiler.results['WASM Initialization'] = wasmInitTime; log(`✅ WASM ready in ${formatMs(wasmInitTime)}`); log(''); window.Docxodus = { DocumentConverter: exports.DocxodusWasm.DocumentConverter, DocumentComparer: exports.DocxodusWasm.DocumentComparer, }; runProfileBtn.disabled = false; runIterationsBtn.disabled = f ``` -------------------------------- ### TypeScript Usage Examples Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/custom_annotations.md Demonstrates how to use the docxodus library in TypeScript to add annotations with various targeting methods. ```APIDOC ### TypeScript Usage ```typescript import { getDocumentStructure, addAnnotationWithTarget, targetParagraph, targetTableCell, targetElement, findElementsByType, DocumentElementType } from 'docxodus'; // Get document structure const structure = await getDocumentStructure(docxBytes); // Find all paragraphs const paragraphs = findElementsByType(structure, DocumentElementType.Paragraph); // Add annotation to first paragraph const result = await addAnnotationWithTarget(docxBytes, { Id: 'ann-1', LabelId: 'IMPORTANT', Label: 'Important Section', Color: '#FFEB3B', ...targetParagraph(0) }); // Add annotation to table cell const cellResult = await addAnnotationWithTarget(docxBytes, { Id: 'ann-2', LabelId: 'DATA', Label: 'Key Data', Color: '#81C784', ...targetTableCell(0, 1, 2) // table 0, row 1, cell 2 }); // Add annotation by element ID const result3 = await addAnnotationWithTarget(docxBytes, { Id: 'ann-3', LabelId: 'REF', Label: 'Reference', Color: '#64B5F6', ...targetElement(paragraphs[0].Id) }); ``` ``` -------------------------------- ### C# Annotation Usage Examples Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/custom_annotations.md Demonstrates how to create and use AnnotationTarget objects to add annotations to specific parts of a document using the AnnotationManager. ```csharp // Target a specific paragraph var target1 = AnnotationTarget.Paragraph(2); // Target a table cell var target2 = AnnotationTarget.TableCell(tableIndex: 0, rowIndex: 1, cellIndex: 2); // Target by element ID from structure analysis var structure = DocumentStructureAnalyzer.Analyze(doc); var cellId = structure.ElementsById.Keys.First(k => k.Contains("/tc-")); var target3 = AnnotationTarget.Element(cellId); // Search within a specific element var target4 = AnnotationTarget.SearchInElement("doc/p-0", "important", occurrence: 1); // Add annotation with target var annotation = new DocumentAnnotation { Id = "ann-1", Label = "My Label", Color = "#FFEB3B" }; var result = AnnotationManager.AddAnnotation(doc, annotation, target1); ``` -------------------------------- ### CSS Font Family Examples Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/docx_converter.md Demonstrates common font family mappings from Word to CSS, including fallbacks. ```css font-family: 'Arial', 'sans-serif' ``` ```css font-family: 'Times New Roman', 'serif' ``` ```css font-family: 'Courier New' ``` -------------------------------- ### Bookmark Hyperlink HTML Example Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/docx_converter.md Demonstrates the HTML representation of a bookmark link within a DOCX document. ```html link text ``` -------------------------------- ### Initialize Docxodus WASM Source: https://github.com/jsv4/docxodus/blob/main/npm/tests/test-harness.html Initializes the Docxodus WebAssembly module and exposes its APIs to the window object for testing purposes. This setup is required before using any Docxodus functionalities. ```javascript import { dotnet } from './\_framework/dotnet.js'; const { getAssemblyExports, getConfig } = await dotnet .withDiagnosticTracing(false) .create(); const config = getConfig(); const exports = await getAssemblyExports(config.mainAssemblyName); // Expose Docxodus APIs to window for testing window.Docxodus = { DocumentConverter: exports.DocxodusWasm.DocumentConverter, DocumentComparer: exports.DocxodusWasm.DocumentComparer }; ``` -------------------------------- ### C#: Full Annotation Workflow Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/incremental_annotation_overlay.md Demonstrates the complete workflow for converting DOCX to HTML, setting up annotations, projecting them, and performing incremental add and remove operations. Includes CSS generation for visibility toggling. ```csharp // Convert once var htmlSettings = new WmlToHtmlConverterSettings(); var baseHtml = WmlToHtmlConverter.ConvertToHtml(doc, htmlSettings).ToString(); // Create annotation set var annotationSet = ExternalAnnotationManager.CreateAnnotationSet(doc, "doc-123"); annotationSet.TextLabels["CLAUSE"] = new AnnotationLabel { Id = "CLAUSE", Text = "Clause", Color = "#FF5722" }; // Create annotations var ann = ExternalAnnotationManager.CreateAnnotation( "ann-1", "CLAUSE", annotationSet.Content, 100, 250); annotationSet.LabelledText.Add(ann); // Project all string annotatedHtml = ExternalAnnotationProjector.ProjectAnnotationsOntoHtml( baseHtml, annotationSet); // Incremental add var ann2 = ExternalAnnotationManager.CreateAnnotation( "ann-2", "CLAUSE", annotationSet.Content, 300, 350); annotatedHtml = ExternalAnnotationProjector.AddAnnotationToHtml( annotatedHtml, ann2, annotationSet.TextLabels["CLAUSE"]); // Incremental remove annotatedHtml = ExternalAnnotationProjector.RemoveAnnotationFromHtml( annotatedHtml, "ann-1"); // Visibility toggle string css = ExternalAnnotationProjector.GenerateVisibilityCss( new[] { "CLAUSE" }); ``` -------------------------------- ### HTML Output for Annotations Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/custom_annotations.md Examples of HTML structure for rendered annotations. Includes variations for floating labels, multi-paragraph spans, and different annotation states (start, continuation, end). ```html Important Clause WHEREAS, the Party of the First Part agrees to...

Important Clause First paragraph of annotated content...

Continuation of annotated content...

Final paragraph of annotated content.

``` -------------------------------- ### Initialize Docxodus WASM Test Harness Source: https://github.com/jsv4/docxodus/blob/main/npm/tests/test-harness.html Sets the status to 'Ready' and marks the Docxodus WASM test harness as available. Logs the version of the loaded Docxodus WASM. ```javascript document.getElementById('status').textContent = 'Ready'; window.DocxodusReady = true; console.log('Docxodus WASM Test Harness Ready'); console.log('Version:', window.DocxodusTests.getVersion()); ``` -------------------------------- ### Build docx2oc from Source Source: https://github.com/jsv4/docxodus/blob/main/tools/docx2oc/README.md Builds the docx2oc tool from its source code. Navigate to the tool's directory and run the build command. ```bash cd tools/docx2oc dotnet build ``` -------------------------------- ### OOXML Comment Range Start Element Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/comment_rendering.md Represents the start of a commented text range in the main document XML. ```xml This text has a comment ``` -------------------------------- ### Build Docxodus from Source Source: https://github.com/jsv4/docxodus/blob/main/README.md Clone the Docxodus repository and build the solution using the .NET CLI. This process prepares the project for local development or custom builds. ```bash # Clone the repository git clone https://github.com/JSv4/Docxodus.git cd Docxodus # Build dotnet build Docxodus.sln # Run the CLI dotnet run --project tools/redline/redline.csproj -- --help ``` -------------------------------- ### Convert DOCX to HTML and Project Annotations Source: https://github.com/jsv4/docxodus/blob/main/docs/npm-package.md Demonstrates the convert-once-then-project pattern. First, convert the DOCX to HTML, then build an annotation set, and finally project the annotations onto the HTML. This is followed by examples of incrementally adding or removing annotations. ```typescript import { initialize, convertDocxToHtml, createExternalAnnotationSet, createAnnotationFromSearch, projectAnnotationsOntoHtml, addAnnotationToHtml, removeAnnotationFromHtml, generateAnnotationVisibilityCss, generateAnnotationCss, } from 'docxodus'; await initialize(); // Step 1: Convert DOCX to HTML once (expensive, ~892ms) const baseHtml = await convertDocxToHtml(docxFile); // Step 2: Build your annotation set const annotationSet = await createExternalAnnotationSet(docxFile, "doc-123"); annotationSet.textLabels["CLAUSE"] = { id: "CLAUSE", text: "Clause", color: "#FF5722", description: "Contract clause", icon: "", labelType: "text" }; const ann = createAnnotationFromSearch( "ann-001", "CLAUSE", annotationSet.content, "shall not be liable" ); if (ann) annotationSet.labelledText.push(ann); // Step 3: Project annotations onto cached HTML (fast, ~56ms) let html = await projectAnnotationsOntoHtml(baseHtml, annotationSet); // Step 4: Incrementally add/remove without re-projecting the full set const newAnn = createAnnotationFromSearch( "ann-002", "CLAUSE", annotationSet.content, "indemnify" ); if (newAnn) { const label = annotationSet.textLabels["CLAUSE"]; html = await addAnnotationToHtml(html, newAnn, label); // ~0.3ms } html = await removeAnnotationFromHtml(html, "ann-001"); // ~0.3ms ``` -------------------------------- ### Build the Entire Docxodus Solution Source: https://github.com/jsv4/docxodus/blob/main/CLAUDE.md Use `dotnet build Docxodus.sln` to compile the entire C# solution. This command is used for a full build of the project. ```bash # Build the entire solution dotnet build Docxodus.sln ``` -------------------------------- ### Example OpenContracts JSON Output Source: https://github.com/jsv4/docxodus/blob/main/tools/docx2oc/README.md An example of the JSON structure produced by docx2oc, compatible with the OpenContracts platform. Includes document title, content, page count, token positions, and structural annotations. ```json { "title": "Sample Contract", "content": "This is the document content...", "pageCount": 5, "pawlsFileContent": [ { "page": { "width": 612, "height": 792, "index": 0 }, "tokens": [ { "x": 72, "y": 72, "width": 30, "height": 12, "text": "This" } ] } ], "labelledText": [ { "id": "section-0", "annotationLabel": "SECTION", "structural": true } ] } ``` -------------------------------- ### Client-Side Rendering with Virtualization Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/wasm-optimization-plan.md Demonstrates client-side rendering of DOCX to HTML, leveraging browser-native content-visibility for efficient rendering of large documents. ```typescript // Simple, fast, minimal API const html = await convertDocxToHtml(docxFile, { paginationMode: PaginationMode.Paginated, renderFootnotesAndEndnotes: true }); // Let browser handle "virtualization" natively container.style.contentVisibility = 'auto'; container.style.containIntrinsicSize = '0 50000px'; container.innerHTML = html; ``` -------------------------------- ### LibreOffice Empty Paragraph HTML Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/wml_to_html_converter_gaps.md Example of how LibreOffice renders an empty paragraph. ```html


``` -------------------------------- ### TypeScript: Full Annotation Workflow Source: https://github.com/jsv4/docxodus/blob/main/docs/architecture/incremental_annotation_overlay.md Demonstrates the complete workflow for converting DOCX to HTML, setting up annotations, projecting them, and performing incremental add and remove operations. Includes CSS generation for visibility toggling. ```typescript import { convertDocxToHtml, createExternalAnnotationSet, projectAnnotationsOntoHtml, addAnnotationToHtml, removeAnnotationFromHtml, generateAnnotationVisibilityCss, createAnnotation, } from "docxodus"; // Step 1: Convert once and cache const baseHtml = await convertDocxToHtml(docxBytes); const annotationSet = await createExternalAnnotationSet(docxBytes, "doc-123"); // Step 2: Define labels annotationSet.textLabels["CLAUSE"] = { id: "CLAUSE", text: "Clause", color: "#FF5722", }; annotationSet.textLabels["TERM"] = { id: "TERM", text: "Term", color: "#2196F3", }; // Step 3: Create annotations and project all at once const ann1 = createAnnotation("ann-1", "CLAUSE", annotationSet.content, 100, 250); const ann2 = createAnnotation("ann-2", "TERM", annotationSet.content, 300, 320); annotationSet.labelledText.push(ann1, ann2); let html = await projectAnnotationsOntoHtml(baseHtml, annotationSet); // Step 4: Incrementally add one more const ann3 = createAnnotation("ann-3", "TERM", annotationSet.content, 500, 530); const termLabel = annotationSet.textLabels["TERM"]; html = await addAnnotationToHtml(html, ann3, termLabel); // Step 5: Remove one html = await removeAnnotationFromHtml(html, "ann-1"); // Step 6: Toggle visibility by label (CSS only, no HTML change) const hideCss = await generateAnnotationVisibilityCss(["TERM"]); // Apply hideCss to a