### 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