Install
openclaw skills install superdocCreate, edit, and manipulate DOCX files using SuperDoc - a modern document editor with custom rendering pipeline. Use when you need to programmatically work...
openclaw skills install superdocSuperDoc is a modern DOCX editor providing programmatic document manipulation with full formatting control.
Installed: v1.17.0 at /usr/local/lib/node_modules/superdoc
const { Document, Paragraph, TextRun } = require('superdoc');
const doc = new Document({
sections: [{
children: [
new Paragraph({
children: [
new TextRun({ text: "Hello World", bold: true })
]
})
]
}]
});
// Save to file
const fs = require('fs');
const Packer = require('superdoc').Packer;
Packer.toBuffer(doc).then(buffer => {
fs.writeFileSync('output.docx', buffer);
});
const { Document } = require('superdoc');
const fs = require('fs');
// Load existing DOCX
const buffer = fs.readFileSync('input.docx');
const doc = await Document.load(buffer);
// Find and replace text
doc.sections[0].children.forEach(para => {
para.children.forEach(run => {
if (run.text) {
run.text = run.text.replace(/Company A/g, 'Company B');
}
});
});
// Save modified document
const output = await Packer.toBuffer(doc);
fs.writeFileSync('output.docx', output);
const { Document, Paragraph, TextRun } = require('superdoc');
const fs = require('fs');
// Load template
const template = fs.readFileSync('template.docx');
// Generate personalized documents
const clients = require('./clients.json');
for (const client of clients) {
const doc = await Document.load(template);
// Replace placeholders
doc.sections[0].children.forEach(para => {
para.children.forEach(run => {
if (run.text) {
run.text = run.text
.replace('{{NAME}}', client.name)
.replace('{{EMAIL}}', client.email);
}
});
});
const output = await Packer.toBuffer(doc);
fs.writeFileSync(`output/${client.id}.docx`, output);
}
Document, Paragraph, TextRun, PackerPacker.toBuffer() or Packer.toBlob()Document.load(buffer)doc.sections[i].children (paragraphs)run.text or formatting propertiesPacker.toBuffer(doc)Common issues:
fs.readFileSync()Document.load() in try-catchSuperDoc requires browser APIs by default. In CLI/headless contexts:
Setup (one-time):
npm install --global superdoc jsdom
Polyfill browser APIs:
const { JSDOM } = require('jsdom');
const dom = new JSDOM('<!DOCTYPE html>');
global.window = dom.window;
global.document = window.document;
global.localStorage = {
getItem: () => null,
setItem: () => {},
removeItem: () => {}
};
// Now import SuperDoc
const { Document } = require('superdoc');
Alternative: Use browser tool
For complex rendering or UI-dependent features, use OpenClaw's browser tool to run SuperDoc in a real browser context.
Install:
npm install @superdoc-dev/react
Basic usage:
import { SuperDocEditor } from '@superdoc-dev/react';
import { useState } from 'react';
function App() {
const [doc, setDoc] = useState(null);
return (
<SuperDocEditor
document={doc}
onChange={setDoc}
onSave={(buffer) => {
// Handle save
const blob = new Blob([buffer], {
type: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
});
// Download or upload blob
}}
/>
);
}
Key props:
document: Document instance or nullonChange: Callback when document changesonSave: Callback with buffer when user savestoolbar: Custom toolbar config (optional)For detailed API reference, advanced formatting, tracked changes, and custom rendering:
"localStorage is not defined" → Add localStorage polyfill (see Headless Usage section)
"Cannot read property 'children' of undefined"
→ Document structure may be empty; check doc.sections.length > 0
Large files slow/crash → Process in batches; consider streaming for files >10MB
Formatting not preserved → Ensure you're modifying properties, not replacing objects