documentation-hub 5.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +43 -0
- package/.github/workflows/build.yml +64 -0
- package/.github/workflows/ci.yml +39 -0
- package/.vscode/extensions.json +3 -0
- package/Current.md +97 -0
- package/DocHub_Image.png +0 -0
- package/README.md +666 -0
- package/USER_GUIDE.md +1173 -0
- package/Updater.md +311 -0
- package/build/256x256.png +0 -0
- package/build/512x512.png +0 -0
- package/build/app-update.yml +4 -0
- package/build/create-icon.js +208 -0
- package/build/icon.ico +0 -0
- package/build/icon.png +0 -0
- package/build/icon_1024x1024.png +0 -0
- package/dist/assets/Analytics-BpsG9895.js +1 -0
- package/dist/assets/Card-IAZin8kp.js +1 -0
- package/dist/assets/CurrentSession-B-rFkHvf.js +12 -0
- package/dist/assets/Dashboard-C_5gMb0q.js +1 -0
- package/dist/assets/Documents-CqZ25axS.js +1 -0
- package/dist/assets/Input-l89xwXBi.js +1 -0
- package/dist/assets/Reporting-DqdHJY_a.js +1 -0
- package/dist/assets/Search-XNbu5z_3.js +1 -0
- package/dist/assets/SessionManager-lH9hZfzH.js +1 -0
- package/dist/assets/Sessions-ClZOPYNc.js +1 -0
- package/dist/assets/Settings-DUEHGURa.js +11 -0
- package/dist/assets/index-8xUe8ptc.js +24 -0
- package/dist/assets/index-RYyJqF7O.css +1 -0
- package/dist/assets/path-BkOl0AGO.js +1 -0
- package/dist/assets/promises-ID_B9S-h.js +1 -0
- package/dist/assets/urlHelpers-TvgahX0r.js +1 -0
- package/dist/assets/useToast-yRSO1dkm.js +1 -0
- package/dist/assets/vendor-charts-RkGK5ROP.js +36 -0
- package/dist/assets/vendor-db-l0sNRNKZ.js +1 -0
- package/dist/assets/vendor-react-BVZ_anCF.js +4 -0
- package/dist/assets/vendor-search-Dw8P0qyA.js +1 -0
- package/dist/assets/vendor-ui-BU7NfluV.js +53 -0
- package/dist/electron/PowerAutomateApiService-LfW09ZGr.js +147 -0
- package/dist/electron/main-CXkNtyv-.js +19789 -0
- package/dist/electron/main.js +5 -0
- package/dist/electron/preload.js +1 -0
- package/dist/icon.png +0 -0
- package/dist/index.html +27 -0
- package/docs/CODEBASE_ANALYSIS_REPORT.md +309 -0
- package/docs/DEBUG_LOGGING_GUIDE.md +244 -0
- package/docs/README.md +115 -0
- package/docs/TOC_WIRING_GUIDE.md +344 -0
- package/docs/analysis/Bullet_Symbol_Bug_Analysis.md +136 -0
- package/docs/analysis/DOCXMLATER_ANALYSIS_SUMMARY.txt +169 -0
- package/docs/analysis/Document_Processing_Issues_Analysis.md +704 -0
- package/docs/analysis/FIELD_PRESERVATION_ANALYSIS.md +1200 -0
- package/docs/analysis/INDENTATION_PRESERVE_ANALYSIS.md +181 -0
- package/docs/analysis/INDENTATION_PRESERVE_IMPLEMENTATION.md +207 -0
- package/docs/analysis/List_Implementation.md +206 -0
- package/docs/analysis/List_Implementation_Accuracy_Report.md +366 -0
- package/docs/analysis/PROCESSING_OPTIONS_UI_UPDATES.md +220 -0
- package/docs/analysis/RefactorStyles.md +852 -0
- package/docs/analysis/STYLE_PARAMETER_ENHANCEMENT.md +143 -0
- package/docs/analysis/docxmlater-comparison-todo-2025-11-13.md +636 -0
- package/docs/analysis/docxmlater-implementation-analysis-2025-11-13.md +340 -0
- package/docs/analysis/docxmlater-template_ui-integration-analysis.md +263 -0
- package/docs/analysis/github-issues-to-create.md +237 -0
- package/docs/api/API_README.md +538 -0
- package/docs/api/API_REFERENCE.md +751 -0
- package/docs/api/TYPE_DEFINITIONS.md +869 -0
- package/docs/architecture/FONT_EMBEDDING_GUIDE.md +318 -0
- package/docs/architecture/docxmlater-functions-and-structure.md +726 -0
- package/docs/docxmlater-readme.md +1341 -0
- package/docs/fixes/EXECUTION_LOG_TEST_BASE.md +573 -0
- package/docs/fixes/HYPERLINK_TEXT_SANITIZATION.md +253 -0
- package/docs/fixes/README.md +37 -0
- package/docs/github-issues/issue-1-body.md +125 -0
- package/docs/github-issues/issue-10-body.md +850 -0
- package/docs/github-issues/issue-2-body.md +200 -0
- package/docs/github-issues/issue-3-body.md +270 -0
- package/docs/github-issues/issue-4-body.md +169 -0
- package/docs/github-issues/issue-5-body.md +173 -0
- package/docs/github-issues/issue-6-body.md +158 -0
- package/docs/github-issues/issue-7-body.md +171 -0
- package/docs/github-issues/issue-8-body.md +407 -0
- package/docs/github-issues/issue-9-body.md +515 -0
- package/docs/github-issues/issue-tracker.md +274 -0
- package/docs/github-issues/predictive-analysis-2025-10-18.md +2131 -0
- package/docs/implementation/List_Framework_Refactor_Plan.md +336 -0
- package/docs/implementation/PRIMARY_TEXT_COLOR_FEATURE.md +217 -0
- package/docs/implementation/RELEASE_PLAN_v2.1.0.md +362 -0
- package/docs/implementation/RefactorStyles.md +588 -0
- package/docs/implementation/implement-plan.md +489 -0
- package/docs/implementation/missing-helpers-implementation.md +391 -0
- package/docs/implementation/refactor-plan.md +520 -0
- package/docs/implementation/session-implementation-complete.md +233 -0
- package/docs/implementation/session-management-plan.md +250 -0
- package/docs/setup-checklist.md +77 -0
- package/docs/versions/changelog.md +345 -0
- package/electron/customUpdater.ts +656 -0
- package/electron/main.ts +2441 -0
- package/electron/memoryConfig.ts +187 -0
- package/electron/preload.ts +394 -0
- package/electron/proxyConfig.ts +340 -0
- package/electron/services/BackupService.ts +452 -0
- package/electron/services/DictionaryService.ts +402 -0
- package/electron/services/LocalDictionaryLookupService.ts +147 -0
- package/electron/services/PowerAutomateApiService.ts +231 -0
- package/electron/services/SharePointSyncService.ts +474 -0
- package/electron/windowsCertStore.ts +427 -0
- package/electron/zscalerConfig.ts +381 -0
- package/eslint.config.js +92 -0
- package/jest.config.js +52 -0
- package/package.json +214 -0
- package/postcss.config.mjs +6 -0
- package/public/icon.png +0 -0
- package/publish-release.ps1 +5 -0
- package/renovate.json +30 -0
- package/src/App.tsx +216 -0
- package/src/__mocks__/p-limit.js +12 -0
- package/src/__mocks__/styleMock.js +1 -0
- package/src/components/common/BugReportButton.tsx +44 -0
- package/src/components/common/BugReportDialog.tsx +193 -0
- package/src/components/common/Button.tsx +153 -0
- package/src/components/common/Card.tsx +86 -0
- package/src/components/common/ColorPickerDialog.tsx +177 -0
- package/src/components/common/ConfirmDialog.tsx +96 -0
- package/src/components/common/DebugConsole.tsx +275 -0
- package/src/components/common/EmptyState.tsx +183 -0
- package/src/components/common/ErrorBoundary.tsx +98 -0
- package/src/components/common/ErrorDetailsDialog.tsx +153 -0
- package/src/components/common/ErrorFallback.tsx +218 -0
- package/src/components/common/Input.tsx +109 -0
- package/src/components/common/Skeleton.tsx +184 -0
- package/src/components/common/SplashScreen.tsx +81 -0
- package/src/components/common/Toast.tsx +155 -0
- package/src/components/common/Tooltip.tsx +79 -0
- package/src/components/common/UpdateNotification.tsx +320 -0
- package/src/components/comparison/ComparisonWindow.tsx +374 -0
- package/src/components/comparison/SideBySideDiff.tsx +486 -0
- package/src/components/comparison/index.ts +8 -0
- package/src/components/document/DocumentUploader.tsx +288 -0
- package/src/components/document/HyperlinkPreview.tsx +430 -0
- package/src/components/document/HyperlinkService.md +1484 -0
- package/src/components/document/Hyperlink_Technical_Documentation.md +496 -0
- package/src/components/document/InlineChangesView.tsx +707 -0
- package/src/components/document/ProcessingProgress.tsx +303 -0
- package/src/components/document/ProcessingResults.tsx +256 -0
- package/src/components/document/TrackedChangesDetail.tsx +530 -0
- package/src/components/document/TrackedChangesPanel.tsx +546 -0
- package/src/components/document/VirtualDocumentList.tsx +240 -0
- package/src/components/editor/DocumentEditor.tsx +723 -0
- package/src/components/editor/DocumentEditorModal.tsx +640 -0
- package/src/components/editor/EditorQuickActions.tsx +502 -0
- package/src/components/editor/EditorToolbar.tsx +312 -0
- package/src/components/editor/TableEditor.tsx +926 -0
- package/src/components/editor/index.ts +18 -0
- package/src/components/layout/Header.tsx +190 -0
- package/src/components/layout/Sidebar.tsx +313 -0
- package/src/components/layout/TitleBar.tsx +190 -0
- package/src/components/navigation/CommandPalette.tsx +233 -0
- package/src/components/navigation/KeyboardShortcutsModal.tsx +173 -0
- package/src/components/sessions/ChangeItem.tsx +408 -0
- package/src/components/sessions/ChangeViewer.tsx +1155 -0
- package/src/components/sessions/DocumentComparisonModal.tsx +314 -0
- package/src/components/sessions/ProcessingOptions.tsx +297 -0
- package/src/components/sessions/ReplacementsTab.tsx +438 -0
- package/src/components/sessions/RevisionHandlingOptions.tsx +87 -0
- package/src/components/sessions/SessionManager.tsx +188 -0
- package/src/components/sessions/StylesEditor.tsx +1335 -0
- package/src/components/sessions/TabContainer.tsx +151 -0
- package/src/components/sessions/VirtualSessionList.tsx +157 -0
- package/src/components/sessions/sessionToProcessorManager.tsx +420 -0
- package/src/components/settings/CertificateManager.tsx +410 -0
- package/src/components/settings/SegmentedControl.tsx +88 -0
- package/src/components/settings/SettingRow.tsx +52 -0
- package/src/contexts/GlobalStatsContext.tsx +396 -0
- package/src/contexts/SessionContext.tsx +2129 -0
- package/src/contexts/ThemeContext.tsx +428 -0
- package/src/contexts/UserSettingsContext.tsx +290 -0
- package/src/contexts/__tests__/GlobalStatsContext.test.tsx +390 -0
- package/src/global.d.ts +273 -0
- package/src/hooks/useDocumentQueue.tsx +210 -0
- package/src/hooks/useToast.tsx +55 -0
- package/src/main.tsx +10 -0
- package/src/pages/Analytics.tsx +386 -0
- package/src/pages/CurrentSession.tsx +1174 -0
- package/src/pages/Dashboard.tsx +319 -0
- package/src/pages/Documents.tsx +317 -0
- package/src/pages/Projects.tsx +250 -0
- package/src/pages/Reporting.tsx +386 -0
- package/src/pages/Search.tsx +349 -0
- package/src/pages/Sessions.tsx +285 -0
- package/src/pages/Settings.tsx +2662 -0
- package/src/services/HyperlinkService.ts +1085 -0
- package/src/services/document/DocXMLaterProcessor.ts +617 -0
- package/src/services/document/DocumentProcessingComparison.ts +856 -0
- package/src/services/document/DocumentSnapshotService.ts +575 -0
- package/src/services/document/WordDocumentProcessor.ts +10509 -0
- package/src/services/document/__tests__/DocXMLaterProcessor.hyperlinks.test.md +311 -0
- package/src/services/document/__tests__/WordDocumentProcessor.integration.test.ts +515 -0
- package/src/services/document/__tests__/WordDocumentProcessor.test.ts +812 -0
- package/src/services/document/blanklines/BlankLineManager.ts +658 -0
- package/src/services/document/blanklines/__tests__/paragraphChecks.test.ts +281 -0
- package/src/services/document/blanklines/helpers/blankLineInsertion.ts +87 -0
- package/src/services/document/blanklines/helpers/blankLineSnapshot.ts +251 -0
- package/src/services/document/blanklines/helpers/clearCustom.ts +121 -0
- package/src/services/document/blanklines/helpers/contextChecks.ts +117 -0
- package/src/services/document/blanklines/helpers/imageChecks.ts +51 -0
- package/src/services/document/blanklines/helpers/paragraphChecks.ts +236 -0
- package/src/services/document/blanklines/helpers/removeBlanksBetweenListItems.ts +91 -0
- package/src/services/document/blanklines/helpers/removeTrailingBlanks.ts +35 -0
- package/src/services/document/blanklines/helpers/tableGuards.ts +21 -0
- package/src/services/document/blanklines/index.ts +67 -0
- package/src/services/document/blanklines/rules/additionRules.ts +337 -0
- package/src/services/document/blanklines/rules/indentationRules.ts +317 -0
- package/src/services/document/blanklines/rules/removalRules.ts +362 -0
- package/src/services/document/blanklines/rules/ruleTypes.ts +92 -0
- package/src/services/document/blanklines/types.ts +29 -0
- package/src/services/document/helpers/ImageBorderCropper.ts +377 -0
- package/src/services/document/helpers/__tests__/whitespace.test.ts +272 -0
- package/src/services/document/helpers/whitespace.ts +117 -0
- package/src/services/document/list/ListNormalizer.ts +947 -0
- package/src/services/document/list/index.ts +45 -0
- package/src/services/document/list/list-detection.ts +275 -0
- package/src/services/document/list/list-types.ts +162 -0
- package/src/services/document/processors/HyperlinkProcessor.ts +370 -0
- package/src/services/document/processors/ListProcessor.ts +257 -0
- package/src/services/document/processors/StructureProcessor.ts +176 -0
- package/src/services/document/processors/StyleProcessor.ts +389 -0
- package/src/services/document/processors/TableProcessor.ts +2238 -0
- package/src/services/document/processors/__tests__/HyperlinkProcessor.test.ts +314 -0
- package/src/services/document/processors/__tests__/ListProcessor.test.ts +291 -0
- package/src/services/document/processors/__tests__/StructureProcessor.test.ts +257 -0
- package/src/services/document/processors/__tests__/TableProcessor.hlp-tips-bullets.test.ts +459 -0
- package/src/services/document/processors/__tests__/TableProcessor.test.ts +1604 -0
- package/src/services/document/processors/index.ts +28 -0
- package/src/services/document/types/docx-processing.ts +310 -0
- package/src/services/editor/EditorActionHandlers.ts +901 -0
- package/src/services/editor/index.ts +13 -0
- package/src/setupTests.ts +47 -0
- package/src/styles/global.css +782 -0
- package/src/types/backup.ts +132 -0
- package/src/types/dictionary.ts +125 -0
- package/src/types/document-processing.ts +331 -0
- package/src/types/docxmlater-augments.d.ts +142 -0
- package/src/types/editor.ts +280 -0
- package/src/types/electron.ts +340 -0
- package/src/types/globalStats.ts +155 -0
- package/src/types/hyperlink.ts +471 -0
- package/src/types/operations.ts +354 -0
- package/src/types/session.ts +427 -0
- package/src/types/settings.ts +112 -0
- package/src/utils/MemoryMonitor.ts +248 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/colorConvert.ts +306 -0
- package/src/utils/diffUtils.ts +347 -0
- package/src/utils/documentUtils.ts +202 -0
- package/src/utils/electronGuard.ts +62 -0
- package/src/utils/indexedDB.ts +915 -0
- package/src/utils/logger.ts +717 -0
- package/src/utils/pathSecurity.ts +232 -0
- package/src/utils/pathValidator.ts +236 -0
- package/src/utils/processingTimeEstimator.ts +153 -0
- package/src/utils/safeJsonParse.ts +62 -0
- package/src/utils/textSanitizer.ts +162 -0
- package/src/utils/urlHelpers.ts +304 -0
- package/src/utils/urlPatterns.ts +198 -0
- package/src/utils/urlSanitizer.ts +152 -0
- package/src/vite-env.d.ts +11 -0
- package/tsconfig.electron.json +19 -0
- package/tsconfig.json +36 -0
- package/tsconfig.node.json +12 -0
- package/typedoc.json +45 -0
- package/vite.config.ts +152 -0
|
@@ -0,0 +1,751 @@
|
|
|
1
|
+
# DocXMLaterProcessor API Reference
|
|
2
|
+
|
|
3
|
+
Complete reference for all public methods in the Documentation Hub's DOCX processing API.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
- [Overview](#overview)
|
|
8
|
+
- [Document I/O Operations](#document-io-operations)
|
|
9
|
+
- [Style Operations](#style-operations)
|
|
10
|
+
- [Table Operations](#table-operations)
|
|
11
|
+
- [Paragraph Formatting](#paragraph-formatting)
|
|
12
|
+
- [High-Level Operations](#high-level-operations)
|
|
13
|
+
- [Hyperlink Operations](#hyperlink-operations)
|
|
14
|
+
- [Search & Replace](#search--replace)
|
|
15
|
+
- [Document Statistics](#document-statistics)
|
|
16
|
+
- [Utility Methods](#utility-methods)
|
|
17
|
+
- [Quick Reference Table](#quick-reference-table)
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
The `DocXMLaterProcessor` class provides a comprehensive API for manipulating Microsoft Word (.docx) documents. It wraps the docxmlater library with enterprise-grade features including:
|
|
22
|
+
|
|
23
|
+
- **Type Safety**: Full TypeScript definitions
|
|
24
|
+
- **Error Handling**: Comprehensive error results
|
|
25
|
+
- **Memory Management**: Automatic resource cleanup
|
|
26
|
+
- **Performance**: Batch operations (30-50% faster for hyperlinks)
|
|
27
|
+
- **Data Integrity**: Defensive text sanitization
|
|
28
|
+
|
|
29
|
+
## Document I/O Operations
|
|
30
|
+
|
|
31
|
+
### loadFromFile(filePath: string)
|
|
32
|
+
|
|
33
|
+
Load a DOCX document from a file path.
|
|
34
|
+
|
|
35
|
+
**Parameters:**
|
|
36
|
+
- `filePath` (string) - Absolute or relative path to the DOCX file
|
|
37
|
+
|
|
38
|
+
**Returns:** `Promise<ProcessorResult<Document>>`
|
|
39
|
+
|
|
40
|
+
**Example:**
|
|
41
|
+
```typescript
|
|
42
|
+
const processor = new DocXMLaterProcessor();
|
|
43
|
+
const result = await processor.loadFromFile('./documents/report.docx');
|
|
44
|
+
|
|
45
|
+
if (result.success) {
|
|
46
|
+
const doc = result.data;
|
|
47
|
+
// Work with document...
|
|
48
|
+
doc.dispose();
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
### loadFromBuffer(buffer: Buffer)
|
|
55
|
+
|
|
56
|
+
Load a DOCX document from a Buffer object.
|
|
57
|
+
|
|
58
|
+
**Parameters:**
|
|
59
|
+
- `buffer` (Buffer) - Buffer containing the DOCX file data
|
|
60
|
+
|
|
61
|
+
**Returns:** `Promise<ProcessorResult<Document>>`
|
|
62
|
+
|
|
63
|
+
**Example:**
|
|
64
|
+
```typescript
|
|
65
|
+
const response = await fetch('https://example.com/document.docx');
|
|
66
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
67
|
+
const buffer = Buffer.from(arrayBuffer);
|
|
68
|
+
|
|
69
|
+
const result = await processor.loadFromBuffer(buffer);
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
### saveToFile(doc: Document, filePath: string)
|
|
75
|
+
|
|
76
|
+
Save a Document to a file path with atomic operations.
|
|
77
|
+
|
|
78
|
+
**Parameters:**
|
|
79
|
+
- `doc` (Document) - Document instance to save
|
|
80
|
+
- `filePath` (string) - Path where the DOCX file will be saved
|
|
81
|
+
|
|
82
|
+
**Returns:** `Promise<ProcessorResult<void>>`
|
|
83
|
+
|
|
84
|
+
**Example:**
|
|
85
|
+
```typescript
|
|
86
|
+
const doc = await processor.loadFromFile('input.docx');
|
|
87
|
+
// Make modifications...
|
|
88
|
+
await processor.saveToFile(doc.data, 'output.docx');
|
|
89
|
+
doc.data.dispose();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
### toBuffer(doc: Document)
|
|
95
|
+
|
|
96
|
+
Convert a Document to a Buffer object for in-memory operations or HTTP transmission.
|
|
97
|
+
|
|
98
|
+
**Parameters:**
|
|
99
|
+
- `doc` (Document) - Document instance to convert
|
|
100
|
+
|
|
101
|
+
**Returns:** `Promise<DocumentModifyResult>`
|
|
102
|
+
|
|
103
|
+
**Example:**
|
|
104
|
+
```typescript
|
|
105
|
+
const result = await processor.toBuffer(doc);
|
|
106
|
+
if (result.success) {
|
|
107
|
+
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document');
|
|
108
|
+
res.send(result.data);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## Style Operations
|
|
115
|
+
|
|
116
|
+
### createDocumentWithStyle(styleId: string, styleName: string, properties: TextStyle & ParagraphStyle)
|
|
117
|
+
|
|
118
|
+
Create a new blank document with a custom paragraph style.
|
|
119
|
+
|
|
120
|
+
**Parameters:**
|
|
121
|
+
- `styleId` (string) - Unique identifier for the style
|
|
122
|
+
- `styleName` (string) - Display name for the style
|
|
123
|
+
- `properties` (TextStyle & ParagraphStyle) - Combined formatting properties
|
|
124
|
+
|
|
125
|
+
**Returns:** `Promise<ProcessorResult<Document>>`
|
|
126
|
+
|
|
127
|
+
**Example:**
|
|
128
|
+
```typescript
|
|
129
|
+
const result = await processor.createDocumentWithStyle(
|
|
130
|
+
'CustomHeading',
|
|
131
|
+
'My Custom Heading',
|
|
132
|
+
{
|
|
133
|
+
fontFamily: 'Arial',
|
|
134
|
+
fontSize: 16,
|
|
135
|
+
bold: true,
|
|
136
|
+
color: '#0066CC',
|
|
137
|
+
alignment: 'left',
|
|
138
|
+
spaceBefore: 240,
|
|
139
|
+
spaceAfter: 120
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
### applyStyleToParagraphs(doc: Document, styleId: string, application: StyleApplication)
|
|
147
|
+
|
|
148
|
+
Apply a style to paragraphs based on target criteria (all, pattern, or specific indices).
|
|
149
|
+
|
|
150
|
+
**Parameters:**
|
|
151
|
+
- `doc` (Document) - Document containing paragraphs to modify
|
|
152
|
+
- `styleId` (string) - ID of the style to apply
|
|
153
|
+
- `application` (StyleApplication) - Targeting criteria
|
|
154
|
+
|
|
155
|
+
**Returns:** `Promise<ProcessorResult<StyleApplicationResult>>`
|
|
156
|
+
|
|
157
|
+
**Example:**
|
|
158
|
+
```typescript
|
|
159
|
+
// Apply to paragraphs containing "IMPORTANT"
|
|
160
|
+
const result = await processor.applyStyleToParagraphs(doc, 'Heading1', {
|
|
161
|
+
target: 'pattern',
|
|
162
|
+
pattern: /IMPORTANT/i
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
console.log(`Applied to ${result.data.appliedCount} paragraphs`);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
## Table Operations
|
|
171
|
+
|
|
172
|
+
### createTable(doc: Document, rows: number, columns: number, options?: TableOptions)
|
|
173
|
+
|
|
174
|
+
Create a formatted table in the document.
|
|
175
|
+
|
|
176
|
+
**Parameters:**
|
|
177
|
+
- `doc` (Document) - Document to add the table to
|
|
178
|
+
- `rows` (number) - Number of rows
|
|
179
|
+
- `columns` (number) - Number of columns
|
|
180
|
+
- `options` (object, optional) - Formatting options
|
|
181
|
+
- `borders` (boolean) - Show borders (default: true)
|
|
182
|
+
- `borderColor` (string) - Border color in hex
|
|
183
|
+
- `borderSize` (number) - Border size in points
|
|
184
|
+
- `headerShading` (string) - Header row background color
|
|
185
|
+
- `cellPadding` (number) - Cell padding in twips
|
|
186
|
+
|
|
187
|
+
**Returns:** `Promise<ProcessorResult<Table>>`
|
|
188
|
+
|
|
189
|
+
**Example:**
|
|
190
|
+
```typescript
|
|
191
|
+
const result = await processor.createTable(doc, 3, 4, {
|
|
192
|
+
borders: true,
|
|
193
|
+
borderColor: '0066CC',
|
|
194
|
+
borderSize: 6,
|
|
195
|
+
headerShading: 'E6F2FF'
|
|
196
|
+
});
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### setCellShading(cell: TableCell, color: string)
|
|
202
|
+
|
|
203
|
+
Set background color (shading) for a table cell.
|
|
204
|
+
|
|
205
|
+
**Parameters:**
|
|
206
|
+
- `cell` (TableCell) - Table cell to apply shading to
|
|
207
|
+
- `color` (string) - Background color in hex format
|
|
208
|
+
|
|
209
|
+
**Returns:** `Promise<ProcessorResult<void>>`
|
|
210
|
+
|
|
211
|
+
**Example:**
|
|
212
|
+
```typescript
|
|
213
|
+
const cell = table.getRow(0).getCell(0);
|
|
214
|
+
await processor.setCellShading(cell, '#E6F2FF');
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
### addCellContent(cell: TableCell, text: string, formatting?: TextStyle)
|
|
220
|
+
|
|
221
|
+
Add formatted text content to a table cell.
|
|
222
|
+
|
|
223
|
+
**Parameters:**
|
|
224
|
+
- `cell` (TableCell) - Table cell to add content to
|
|
225
|
+
- `text` (string) - Text content to add
|
|
226
|
+
- `formatting` (TextStyle, optional) - Text formatting options
|
|
227
|
+
|
|
228
|
+
**Returns:** `Promise<ProcessorResult<void>>`
|
|
229
|
+
|
|
230
|
+
**Example:**
|
|
231
|
+
```typescript
|
|
232
|
+
await processor.addCellContent(headerCell, 'Product Name', {
|
|
233
|
+
bold: true,
|
|
234
|
+
fontSize: 12,
|
|
235
|
+
color: '#FFFFFF'
|
|
236
|
+
});
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
---
|
|
240
|
+
|
|
241
|
+
## Paragraph Formatting
|
|
242
|
+
|
|
243
|
+
### createParagraph(doc: Document, text: string, formatting?: ParagraphStyle & TextStyle)
|
|
244
|
+
|
|
245
|
+
Create a formatted paragraph in the document.
|
|
246
|
+
|
|
247
|
+
**Parameters:**
|
|
248
|
+
- `doc` (Document) - Document to add paragraph to
|
|
249
|
+
- `text` (string) - Text content for the paragraph
|
|
250
|
+
- `formatting` (ParagraphStyle & TextStyle, optional) - Formatting options
|
|
251
|
+
|
|
252
|
+
**Returns:** `Promise<ProcessorResult<Paragraph>>`
|
|
253
|
+
|
|
254
|
+
**Example:**
|
|
255
|
+
```typescript
|
|
256
|
+
const result = await processor.createParagraph(doc, 'Chapter 1: Introduction', {
|
|
257
|
+
fontFamily: 'Arial',
|
|
258
|
+
fontSize: 16,
|
|
259
|
+
bold: true,
|
|
260
|
+
color: '#0066CC',
|
|
261
|
+
alignment: 'left',
|
|
262
|
+
spaceBefore: 240,
|
|
263
|
+
spaceAfter: 120,
|
|
264
|
+
keepNext: true
|
|
265
|
+
});
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
### setIndentation(para: Paragraph, options: IndentationOptions)
|
|
271
|
+
|
|
272
|
+
Set indentation on an existing paragraph.
|
|
273
|
+
|
|
274
|
+
**Parameters:**
|
|
275
|
+
- `para` (Paragraph) - Paragraph to modify
|
|
276
|
+
- `options` (object) - Indentation settings
|
|
277
|
+
- `left` (number, optional) - Left indentation in twips
|
|
278
|
+
- `right` (number, optional) - Right indentation in twips
|
|
279
|
+
- `firstLine` (number, optional) - First line indentation in twips
|
|
280
|
+
|
|
281
|
+
**Returns:** `Promise<ProcessorResult<void>>`
|
|
282
|
+
|
|
283
|
+
**Example:**
|
|
284
|
+
```typescript
|
|
285
|
+
// Set hanging indent for bibliography
|
|
286
|
+
await processor.setIndentation(paragraphs[0], {
|
|
287
|
+
left: processor.inchesToTwips(0.5),
|
|
288
|
+
firstLine: processor.inchesToTwips(-0.25)
|
|
289
|
+
});
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## High-Level Operations
|
|
295
|
+
|
|
296
|
+
### readDocument(filePath: string)
|
|
297
|
+
|
|
298
|
+
Read an existing document and extract its complete structure.
|
|
299
|
+
|
|
300
|
+
**Parameters:**
|
|
301
|
+
- `filePath` (string) - Path to the DOCX file to read
|
|
302
|
+
|
|
303
|
+
**Returns:** `Promise<DocumentReadResult>`
|
|
304
|
+
|
|
305
|
+
**Example:**
|
|
306
|
+
```typescript
|
|
307
|
+
const result = await processor.readDocument('./report.docx');
|
|
308
|
+
|
|
309
|
+
if (result.success) {
|
|
310
|
+
console.log(`Paragraphs: ${result.data.content.paragraphs.length}`);
|
|
311
|
+
console.log(`Tables: ${result.data.content.tables.length}`);
|
|
312
|
+
}
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
### modifyDocument(filePath: string, modifications: (doc: Document) => Promise<void> | void)
|
|
318
|
+
|
|
319
|
+
Perform atomic load-modify-save operations on a document.
|
|
320
|
+
|
|
321
|
+
**Parameters:**
|
|
322
|
+
- `filePath` (string) - Path to the DOCX file to modify
|
|
323
|
+
- `modifications` (function) - Function that receives the document and makes modifications
|
|
324
|
+
|
|
325
|
+
**Returns:** `Promise<DocumentModifyResult>`
|
|
326
|
+
|
|
327
|
+
**Example:**
|
|
328
|
+
```typescript
|
|
329
|
+
await processor.modifyDocument('./contract.docx', async (doc) => {
|
|
330
|
+
doc.replaceText('COMPANY_NAME', 'Acme Corporation');
|
|
331
|
+
doc.replaceText('CURRENT_YEAR', '2025');
|
|
332
|
+
});
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
### modifyDocumentBuffer(buffer: Buffer, modifications: (doc: Document) => Promise<void> | void)
|
|
338
|
+
|
|
339
|
+
Perform atomic load-modify operations on a document from Buffer.
|
|
340
|
+
|
|
341
|
+
**Parameters:**
|
|
342
|
+
- `buffer` (Buffer) - Buffer containing the DOCX file data
|
|
343
|
+
- `modifications` (function) - Function that receives the document and makes modifications
|
|
344
|
+
|
|
345
|
+
**Returns:** `Promise<DocumentModifyResult>`
|
|
346
|
+
|
|
347
|
+
**Example:**
|
|
348
|
+
```typescript
|
|
349
|
+
const result = await processor.modifyDocumentBuffer(inputBuffer, async (doc) => {
|
|
350
|
+
const para = doc.createParagraph('CONFIDENTIAL');
|
|
351
|
+
para.setAlignment('center');
|
|
352
|
+
});
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Hyperlink Operations
|
|
358
|
+
|
|
359
|
+
### extractHyperlinks(doc: Document)
|
|
360
|
+
|
|
361
|
+
Extract all hyperlinks from a document with comprehensive coverage (body, tables, headers, footers).
|
|
362
|
+
|
|
363
|
+
**Performance:** 89% code reduction, 20-30% faster than manual extraction
|
|
364
|
+
|
|
365
|
+
**Parameters:**
|
|
366
|
+
- `doc` (Document) - Document to extract hyperlinks from
|
|
367
|
+
|
|
368
|
+
**Returns:** `Promise<Array<HyperlinkInfo>>`
|
|
369
|
+
|
|
370
|
+
**Example:**
|
|
371
|
+
```typescript
|
|
372
|
+
const hyperlinks = await processor.extractHyperlinks(doc);
|
|
373
|
+
|
|
374
|
+
hyperlinks.forEach((link, index) => {
|
|
375
|
+
console.log(`${index + 1}. ${link.text}`);
|
|
376
|
+
console.log(` URL: ${link.url}`);
|
|
377
|
+
});
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
---
|
|
381
|
+
|
|
382
|
+
### updateHyperlinkUrls(doc: Document, urlMap: Map<string, string>)
|
|
383
|
+
|
|
384
|
+
Batch update hyperlink URLs using direct mapping.
|
|
385
|
+
|
|
386
|
+
**Performance:** 30-50% faster than modifyHyperlinks for simple replacements
|
|
387
|
+
|
|
388
|
+
**Parameters:**
|
|
389
|
+
- `doc` (Document) - Document to modify
|
|
390
|
+
- `urlMap` (Map<string, string>) - Map of old URLs to new URLs
|
|
391
|
+
|
|
392
|
+
**Returns:** `Promise<ProcessorResult<UpdateStats>>`
|
|
393
|
+
|
|
394
|
+
**Example:**
|
|
395
|
+
```typescript
|
|
396
|
+
const urlMap = new Map([
|
|
397
|
+
['http://old-site.com/page1', 'https://new-site.com/page1'],
|
|
398
|
+
['http://old-site.com/page2', 'https://new-site.com/page2']
|
|
399
|
+
]);
|
|
400
|
+
|
|
401
|
+
const result = await processor.updateHyperlinkUrls(doc, urlMap);
|
|
402
|
+
console.log(`Updated: ${result.data.modifiedHyperlinks}`);
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
### modifyHyperlinks(doc: Document, urlTransform: (url: string, displayText: string) => string)
|
|
408
|
+
|
|
409
|
+
Modify hyperlinks using a transformation function.
|
|
410
|
+
|
|
411
|
+
**Parameters:**
|
|
412
|
+
- `doc` (Document) - Document to modify
|
|
413
|
+
- `urlTransform` (function) - Function that receives URL and text, returns new URL
|
|
414
|
+
|
|
415
|
+
**Returns:** `Promise<ProcessorResult<ModifyStats>>`
|
|
416
|
+
|
|
417
|
+
**Example:**
|
|
418
|
+
```typescript
|
|
419
|
+
// Upgrade HTTP to HTTPS
|
|
420
|
+
await processor.modifyHyperlinks(doc, (url, displayText) => {
|
|
421
|
+
if (url.startsWith('http://') && url.includes('example.com')) {
|
|
422
|
+
return url.replace('http://', 'https://');
|
|
423
|
+
}
|
|
424
|
+
return url;
|
|
425
|
+
});
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
---
|
|
429
|
+
|
|
430
|
+
### appendContentIdToTheSourceUrls(filePath: string, contentId?: string)
|
|
431
|
+
|
|
432
|
+
Append Content ID fragment to theSource URLs (CVS Health specific).
|
|
433
|
+
|
|
434
|
+
**Parameters:**
|
|
435
|
+
- `filePath` (string) - Path to the DOCX file to modify
|
|
436
|
+
- `contentId` (string, optional) - Content fragment to append (default: '#content')
|
|
437
|
+
|
|
438
|
+
**Returns:** `Promise<ProcessorResult<UpdateStats>>`
|
|
439
|
+
|
|
440
|
+
**Example:**
|
|
441
|
+
```typescript
|
|
442
|
+
const result = await processor.appendContentIdToTheSourceUrls('./document.docx');
|
|
443
|
+
// Transforms: thesource.cvshealth.com/page/docid=abc -> ...#content
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
---
|
|
447
|
+
|
|
448
|
+
### replaceHyperlinkText(doc: Document, pattern: string | RegExp, replacement: string)
|
|
449
|
+
|
|
450
|
+
Replace hyperlink display text based on a pattern.
|
|
451
|
+
|
|
452
|
+
**Parameters:**
|
|
453
|
+
- `doc` (Document) - Document to modify
|
|
454
|
+
- `pattern` (string | RegExp) - Pattern to match in display text
|
|
455
|
+
- `replacement` (string) - Replacement text
|
|
456
|
+
|
|
457
|
+
**Returns:** `Promise<ProcessorResult<ReplaceStats>>`
|
|
458
|
+
|
|
459
|
+
**Example:**
|
|
460
|
+
```typescript
|
|
461
|
+
// Regex replacement with capture groups
|
|
462
|
+
await processor.replaceHyperlinkText(doc, /Page (\d+)/, 'Section $1');
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
## Search & Replace
|
|
468
|
+
|
|
469
|
+
### findText(doc: Document, pattern: string | RegExp, options?: SearchOptions)
|
|
470
|
+
|
|
471
|
+
Find text in document using built-in search.
|
|
472
|
+
|
|
473
|
+
**Parameters:**
|
|
474
|
+
- `doc` (Document) - Document to search
|
|
475
|
+
- `pattern` (string | RegExp) - Text string or regex pattern
|
|
476
|
+
- `options` (object, optional)
|
|
477
|
+
- `caseSensitive` (boolean) - Case-sensitive search
|
|
478
|
+
- `wholeWord` (boolean) - Match whole words only
|
|
479
|
+
|
|
480
|
+
**Returns:** `Promise<ProcessorResult<Array<SearchResult>>>`
|
|
481
|
+
|
|
482
|
+
**Example:**
|
|
483
|
+
```typescript
|
|
484
|
+
const result = await processor.findText(doc, 'important', {
|
|
485
|
+
caseSensitive: false
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
console.log(`Found ${result.data.length} matches`);
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
### replaceText(doc: Document, find: string | RegExp, replace: string, options?: ReplaceOptions)
|
|
494
|
+
|
|
495
|
+
Replace text in document using built-in replace.
|
|
496
|
+
|
|
497
|
+
**Parameters:**
|
|
498
|
+
- `doc` (Document) - Document to modify
|
|
499
|
+
- `find` (string | RegExp) - Text or pattern to find
|
|
500
|
+
- `replace` (string) - Replacement text
|
|
501
|
+
- `options` (object, optional)
|
|
502
|
+
- `caseSensitive` (boolean) - Case-sensitive search
|
|
503
|
+
- `wholeWord` (boolean) - Match whole words only
|
|
504
|
+
|
|
505
|
+
**Returns:** `Promise<ProcessorResult<ReplaceStats>>`
|
|
506
|
+
|
|
507
|
+
**Example:**
|
|
508
|
+
```typescript
|
|
509
|
+
// Simple text replacement
|
|
510
|
+
await processor.replaceText(doc, '{{COMPANY_NAME}}', 'Acme Corporation');
|
|
511
|
+
|
|
512
|
+
// Regex replacement with capture groups
|
|
513
|
+
await processor.replaceText(doc, /(\d{2})\/(\d{2})\/(\d{4})/, '$3-$1-$2');
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
---
|
|
517
|
+
|
|
518
|
+
## Document Statistics
|
|
519
|
+
|
|
520
|
+
### getWordCount(doc: Document)
|
|
521
|
+
|
|
522
|
+
Get word count from document (includes paragraphs, tables, headers, footers).
|
|
523
|
+
|
|
524
|
+
**Parameters:**
|
|
525
|
+
- `doc` (Document) - Document to analyze
|
|
526
|
+
|
|
527
|
+
**Returns:** `Promise<ProcessorResult<{ wordCount: number }>>`
|
|
528
|
+
|
|
529
|
+
**Example:**
|
|
530
|
+
```typescript
|
|
531
|
+
const result = await processor.getWordCount(doc);
|
|
532
|
+
console.log(`Document contains ${result.data.wordCount} words`);
|
|
533
|
+
|
|
534
|
+
// Calculate reading time (200 words per minute)
|
|
535
|
+
const readingTime = Math.ceil(result.data.wordCount / 200);
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
### getCharacterCount(doc: Document, includeSpaces?: boolean)
|
|
541
|
+
|
|
542
|
+
Get character count from document.
|
|
543
|
+
|
|
544
|
+
**Parameters:**
|
|
545
|
+
- `doc` (Document) - Document to analyze
|
|
546
|
+
- `includeSpaces` (boolean, optional) - Include spaces in count (default: true)
|
|
547
|
+
|
|
548
|
+
**Returns:** `Promise<ProcessorResult<{ characterCount: number }>>`
|
|
549
|
+
|
|
550
|
+
**Example:**
|
|
551
|
+
```typescript
|
|
552
|
+
const withSpaces = await processor.getCharacterCount(doc, true);
|
|
553
|
+
const withoutSpaces = await processor.getCharacterCount(doc, false);
|
|
554
|
+
|
|
555
|
+
console.log(`Characters (with spaces): ${withSpaces.data.characterCount}`);
|
|
556
|
+
console.log(`Characters (no spaces): ${withoutSpaces.data.characterCount}`);
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
---
|
|
560
|
+
|
|
561
|
+
### estimateSize(doc: Document)
|
|
562
|
+
|
|
563
|
+
Estimate document size before saving.
|
|
564
|
+
|
|
565
|
+
**Parameters:**
|
|
566
|
+
- `doc` (Document) - Document to estimate
|
|
567
|
+
|
|
568
|
+
**Returns:** `Promise<ProcessorResult<{ totalEstimatedMB: number, warning?: string }>>`
|
|
569
|
+
|
|
570
|
+
**Example:**
|
|
571
|
+
```typescript
|
|
572
|
+
const sizeResult = await processor.estimateSize(doc);
|
|
573
|
+
console.log(`Estimated size: ${sizeResult.data.totalEstimatedMB.toFixed(2)} MB`);
|
|
574
|
+
|
|
575
|
+
if (sizeResult.data.totalEstimatedMB < 10) {
|
|
576
|
+
await processor.saveToFile(doc, 'output.docx');
|
|
577
|
+
} else {
|
|
578
|
+
console.error('Document too large');
|
|
579
|
+
}
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
---
|
|
583
|
+
|
|
584
|
+
### getSizeStats(doc: Document)
|
|
585
|
+
|
|
586
|
+
Get detailed document statistics including element counts and size.
|
|
587
|
+
|
|
588
|
+
**Parameters:**
|
|
589
|
+
- `doc` (Document) - Document to analyze
|
|
590
|
+
|
|
591
|
+
**Returns:** `Promise<ProcessorResult<SizeStats>>`
|
|
592
|
+
|
|
593
|
+
**Example:**
|
|
594
|
+
```typescript
|
|
595
|
+
const stats = await processor.getSizeStats(doc);
|
|
596
|
+
|
|
597
|
+
console.log(`Paragraphs: ${stats.data.elements.paragraphs}`);
|
|
598
|
+
console.log(`Tables: ${stats.data.elements.tables}`);
|
|
599
|
+
console.log(`Images: ${stats.data.elements.images}`);
|
|
600
|
+
console.log(`Hyperlinks: ${stats.data.elements.hyperlinks}`);
|
|
601
|
+
console.log(`Size: ${stats.data.size.totalEstimatedMB.toFixed(2)} MB`);
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
---
|
|
605
|
+
|
|
606
|
+
## Utility Methods
|
|
607
|
+
|
|
608
|
+
### createNewDocument()
|
|
609
|
+
|
|
610
|
+
Create a new blank document.
|
|
611
|
+
|
|
612
|
+
**Returns:** `Document`
|
|
613
|
+
|
|
614
|
+
**Example:**
|
|
615
|
+
```typescript
|
|
616
|
+
const doc = processor.createNewDocument();
|
|
617
|
+
await processor.createParagraph(doc, 'Hello World!');
|
|
618
|
+
await processor.saveToFile(doc, 'new-document.docx');
|
|
619
|
+
doc.dispose();
|
|
620
|
+
```
|
|
621
|
+
|
|
622
|
+
---
|
|
623
|
+
|
|
624
|
+
### inchesToTwips(inches: number)
|
|
625
|
+
|
|
626
|
+
Convert inches to twips (1 inch = 1440 twips).
|
|
627
|
+
|
|
628
|
+
**Parameters:**
|
|
629
|
+
- `inches` (number) - Measurement in inches
|
|
630
|
+
|
|
631
|
+
**Returns:** `number`
|
|
632
|
+
|
|
633
|
+
**Example:**
|
|
634
|
+
```typescript
|
|
635
|
+
const indent = processor.inchesToTwips(0.5); // 720 twips
|
|
636
|
+
await processor.setIndentation(para, { left: indent });
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
---
|
|
640
|
+
|
|
641
|
+
### pointsToTwips(points: number)
|
|
642
|
+
|
|
643
|
+
Convert points to twips (1 point = 20 twips).
|
|
644
|
+
|
|
645
|
+
**Parameters:**
|
|
646
|
+
- `points` (number) - Measurement in points
|
|
647
|
+
|
|
648
|
+
**Returns:** `number`
|
|
649
|
+
|
|
650
|
+
**Example:**
|
|
651
|
+
```typescript
|
|
652
|
+
const spacing = processor.pointsToTwips(12); // 240 twips
|
|
653
|
+
await processor.createParagraph(doc, 'Text', { spaceBefore: spacing });
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
---
|
|
657
|
+
|
|
658
|
+
### twipsToPoints(twips: number)
|
|
659
|
+
|
|
660
|
+
Convert twips to points (20 twips = 1 point).
|
|
661
|
+
|
|
662
|
+
**Parameters:**
|
|
663
|
+
- `twips` (number) - Measurement in twips
|
|
664
|
+
|
|
665
|
+
**Returns:** `number`
|
|
666
|
+
|
|
667
|
+
**Example:**
|
|
668
|
+
```typescript
|
|
669
|
+
const formatting = para.getFormatting();
|
|
670
|
+
const points = processor.twipsToPoints(formatting.spaceBefore);
|
|
671
|
+
console.log(`Space before: ${points}pt`);
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
---
|
|
675
|
+
|
|
676
|
+
## Quick Reference Table
|
|
677
|
+
|
|
678
|
+
| Method | Category | Description | Returns |
|
|
679
|
+
|--------|----------|-------------|---------|
|
|
680
|
+
| `loadFromFile` | Document I/O | Load document from file path | `Promise<ProcessorResult<Document>>` |
|
|
681
|
+
| `loadFromBuffer` | Document I/O | Load document from Buffer | `Promise<ProcessorResult<Document>>` |
|
|
682
|
+
| `saveToFile` | Document I/O | Save document to file path | `Promise<ProcessorResult<void>>` |
|
|
683
|
+
| `toBuffer` | Document I/O | Convert document to Buffer | `Promise<DocumentModifyResult>` |
|
|
684
|
+
| `createDocumentWithStyle` | Style Operations | Create document with custom style | `Promise<ProcessorResult<Document>>` |
|
|
685
|
+
| `applyStyleToParagraphs` | Style Operations | Apply style to paragraphs | `Promise<ProcessorResult<StyleApplicationResult>>` |
|
|
686
|
+
| `createTable` | Table Operations | Create formatted table | `Promise<ProcessorResult<Table>>` |
|
|
687
|
+
| `setCellShading` | Table Operations | Set cell background color | `Promise<ProcessorResult<void>>` |
|
|
688
|
+
| `addCellContent` | Table Operations | Add content to table cell | `Promise<ProcessorResult<void>>` |
|
|
689
|
+
| `createParagraph` | Paragraph Formatting | Create formatted paragraph | `Promise<ProcessorResult<Paragraph>>` |
|
|
690
|
+
| `setIndentation` | Paragraph Formatting | Set paragraph indentation | `Promise<ProcessorResult<void>>` |
|
|
691
|
+
| `readDocument` | High-Level Operations | Read document structure | `Promise<DocumentReadResult>` |
|
|
692
|
+
| `modifyDocument` | High-Level Operations | Atomic load-modify-save | `Promise<DocumentModifyResult>` |
|
|
693
|
+
| `modifyDocumentBuffer` | High-Level Operations | Modify document from Buffer | `Promise<DocumentModifyResult>` |
|
|
694
|
+
| `extractHyperlinks` | Hyperlink Operations | Extract all hyperlinks | `Promise<Array<HyperlinkInfo>>` |
|
|
695
|
+
| `updateHyperlinkUrls` | Hyperlink Operations | Batch update hyperlink URLs | `Promise<ProcessorResult<UpdateStats>>` |
|
|
696
|
+
| `modifyHyperlinks` | Hyperlink Operations | Transform hyperlink URLs | `Promise<ProcessorResult<ModifyStats>>` |
|
|
697
|
+
| `appendContentIdToTheSourceUrls` | Hyperlink Operations | Append #content to theSource | `Promise<ProcessorResult<UpdateStats>>` |
|
|
698
|
+
| `replaceHyperlinkText` | Hyperlink Operations | Replace hyperlink display text | `Promise<ProcessorResult<ReplaceStats>>` |
|
|
699
|
+
| `findText` | Search & Replace | Find text in document | `Promise<ProcessorResult<Array<SearchResult>>>` |
|
|
700
|
+
| `replaceText` | Search & Replace | Replace text in document | `Promise<ProcessorResult<ReplaceStats>>` |
|
|
701
|
+
| `getWordCount` | Document Statistics | Get word count | `Promise<ProcessorResult<{ wordCount: number }>>` |
|
|
702
|
+
| `getCharacterCount` | Document Statistics | Get character count | `Promise<ProcessorResult<{ characterCount: number }>>` |
|
|
703
|
+
| `estimateSize` | Document Statistics | Estimate document size | `Promise<ProcessorResult<SizeEstimate>>` |
|
|
704
|
+
| `getSizeStats` | Document Statistics | Get detailed statistics | `Promise<ProcessorResult<SizeStats>>` |
|
|
705
|
+
| `createNewDocument` | Utilities | Create blank document | `Document` |
|
|
706
|
+
| `inchesToTwips` | Utilities | Convert inches to twips | `number` |
|
|
707
|
+
| `pointsToTwips` | Utilities | Convert points to twips | `number` |
|
|
708
|
+
| `twipsToPoints` | Utilities | Convert twips to points | `number` |
|
|
709
|
+
|
|
710
|
+
---
|
|
711
|
+
|
|
712
|
+
## Notes
|
|
713
|
+
|
|
714
|
+
### Memory Management
|
|
715
|
+
|
|
716
|
+
Always call `dispose()` on documents when finished to prevent memory leaks:
|
|
717
|
+
|
|
718
|
+
```typescript
|
|
719
|
+
const loadResult = await processor.loadFromFile('document.docx');
|
|
720
|
+
if (loadResult.success) {
|
|
721
|
+
const doc = loadResult.data;
|
|
722
|
+
// Work with document...
|
|
723
|
+
doc.dispose(); // Clean up
|
|
724
|
+
}
|
|
725
|
+
```
|
|
726
|
+
|
|
727
|
+
### Error Handling
|
|
728
|
+
|
|
729
|
+
All methods return `ProcessorResult<T>` objects with success/error information:
|
|
730
|
+
|
|
731
|
+
```typescript
|
|
732
|
+
const result = await processor.loadFromFile('file.docx');
|
|
733
|
+
if (!result.success) {
|
|
734
|
+
console.error('Error:', result.error);
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
const doc = result.data;
|
|
738
|
+
```
|
|
739
|
+
|
|
740
|
+
### Performance Tips
|
|
741
|
+
|
|
742
|
+
1. Use `updateHyperlinkUrls()` for direct URL mapping (30-50% faster)
|
|
743
|
+
2. Use batch operations when possible
|
|
744
|
+
3. Dispose documents immediately after use
|
|
745
|
+
4. Use `modifyDocument()` for atomic operations
|
|
746
|
+
|
|
747
|
+
---
|
|
748
|
+
|
|
749
|
+
**Last Updated:** 2025-11-13
|
|
750
|
+
**Version:** 1.0.40
|
|
751
|
+
**Documentation Hub** | [GitHub](https://github.com/ItMeDiaTech/Documentation_Hub)
|