Files
docx/api/index.html

175 lines
35 KiB
HTML

<!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>docx</title><meta name="description" content="Documentation for docx"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script><script async src="assets/hierarchy.js" id="tsd-hierarchy-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar">
<div class="tsd-toolbar-contents container"><a href="index.html" class="title">docx</a>
<div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/>
<ul role="listbox" id="tsd-search-results"></ul>
<div id="tsd-search-status" aria-live="polite" aria-atomic="true">
<div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></header>
<div class="container container-main">
<div class="col-content">
<div class="tsd-page-title">
<h1>docx</h1></div>
<div class="tsd-panel tsd-typography"><p align="center">
<img src="media/logo-animate.svg" width="100%" height="300" alt="clippy the assistant">
</p>
<p align="center">
Easily generate and modify .docx files with JS/TS. Works for Node and on the Browser.
</p>
<hr>
<p><a href="https://npmjs.org/package/docx"><img src="https://badge.fury.io/js/docx.svg" alt="NPM version"></a>
<a href="https://npmjs.org/package/docx"><img src="https://img.shields.io/npm/dm/docx.svg" alt="Downloads per month"></a>
<a href="https://github.com/dolanmiu/docx/actions/workflows/default.yml"><img src="https://github.com/dolanmiu/docx/actions/workflows/default.yml/badge.svg?branch=master" alt="GitHub Action Workflow Status"></a>
<a href="https://snyk.io/test/github/dolanmiu/docx"><img src="https://snyk.io/test/github/dolanmiu/docx/badge.svg" alt="Known Vulnerabilities"></a>
<a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome"></a>
<a href="https://codecov.io/gh/dolanmiu/docx"><img src="https://codecov.io/gh/dolanmiu/docx/branch/master/graph/badge.svg" alt="codecov"></a>
<a href="https://docxjs-editor.vercel.app/"><img src="https://img.shields.io/badge/Docx.js%20Editor-2b579a.svg?style=flat&amp;logo=javascript&amp;logoColor=white" alt="Docx.js Editor"></a></p>
<p align="center">
<img src="https://i.imgur.com/QeL1HuU.png" alt="drawing"/>
</p>
<h1 id="demo" class="tsd-anchor-link">Demo<a href="#demo" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<h2 id="browser" class="tsd-anchor-link">Browser<a href="#browser" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
<p>With basic <code>HTML/JS</code> in a browser, load <code>docx</code>'s browser build, which defines a global <code>docx</code>:</p>
<pre><code class="html"><!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/docx@9/dist/index.iife.js"></script>
</head>
<body>
<button type="button" onclick="generate()">Download a Word document</button>
<script>
function generate() {
const doc = new docx.Document({
sections: [
{
children: [
new docx.Paragraph({
children: [new docx.TextRun("Hello World"), new docx.TextRun({ text: "Foo Bar", bold: true })],
}),
],
},
],
});
docx.Packer.toBlob(doc).then((blob) => {
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "example.docx";
link.click();
});
}
</script>
</body>
</html>
</code><button type="button">Copy</button></pre>
<p>Here are examples of <code>docx</code> working in <code>Angular</code>:</p>
<ul>
<li><a href="https://stackblitz.com/edit/angular-docx">https://stackblitz.com/edit/angular-docx</a></li>
<li><a href="https://stackblitz.com/edit/angular-wmd6k3">https://stackblitz.com/edit/angular-wmd6k3</a></li>
</ul>
<p>Here are examples of <code>docx</code> working in <code>React</code>:</p>
<ul>
<li><a href="https://stackblitz.com/edit/react-docx">https://stackblitz.com/edit/react-docx</a></li>
<li><a href="https://stackblitz.com/edit/react-docx-images">https://stackblitz.com/edit/react-docx-images</a> (adding images to Word Document)</li>
</ul>
<p>Here is an example of <code>docx</code> working in <code>Vue.js</code>:</p>
<ul>
<li><a href="https://stackblitz.com/edit/vuejs-docx">https://stackblitz.com/edit/vuejs-docx</a></li>
</ul>
<h2 id="node" class="tsd-anchor-link">Node<a href="#node" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2>
<p>Runnable examples live in <a href="https://github.com/dolanmiu/docx/tree/master/demo"><code>demo/</code></a>, grouped by topic. In a clone of this repository, after <code>npm install</code> and <code>npm run build</code>, run one with <code>npm run run-ts -- ./demo/&lt;topic&gt;/&lt;demo&gt;.ts</code>; it writes <code>My Document.docx</code> to the root of the repository.</p>
<ul>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/getting-started/basic-document.ts"><code>demo/getting-started/basic-document.ts</code></a> - Simple paragraph and text</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/styles/default-styles.ts"><code>demo/styles/default-styles.ts</code></a> - Advanced paragraphs and text</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/lists/numbering-and-bullet-points.ts"><code>demo/lists/numbering-and-bullet-points.ts</code></a> - Bullet points and numbering</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/tables/basic-table.ts"><code>demo/tables/basic-table.ts</code></a> - Simple table</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/images/images.ts"><code>demo/images/images.ts</code></a> - Images</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/page-layout/page-borders.ts"><code>demo/page-layout/page-borders.ts</code></a> - Margins</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/page-layout/landscape.ts"><code>demo/page-layout/landscape.ts</code></a> - Landscape</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/headers-and-footers/header-and-footer.ts"><code>demo/headers-and-footers/header-and-footer.ts</code></a> - Header and Footer</li>
<li><a href="https://github.com/dolanmiu/docx/blob/master/demo/getting-started/cv.ts"><code>demo/getting-started/cv.ts</code></a> - <strong>My CV generated with docx</strong></li>
</ul>
<h1 id="how-to-use-documentation" class="tsd-anchor-link">How to use &amp; Documentation<a href="#how-to-use-documentation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Please refer to the <a href="https://docx.js.org/">documentation at https://docx.js.org/</a> for details on how to use this library, examples and much more!</p>
<h1 id="shapes-watermarks-and-charts" class="tsd-anchor-link">Shapes, watermarks and charts<a href="#shapes-watermarks-and-charts" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Shapes, groups of shapes and diagrams with connectors come with <code>docx</code>, from <code>docx/shapes</code>, watermarks from <code>docx/watermarks</code>, and native Word charts from <code>docx/charts</code>. They are left out of <code>docx</code> itself, so documents that don't use them don't carry their code:</p>
<pre><code class="ts"><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">Document</span><span class="hl-1">, </span><span class="hl-2">Header</span><span class="hl-1">, </span><span class="hl-2">Paragraph</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">ChartRun</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/charts&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">ShapeRun</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/shapes&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">TextWatermark</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/watermarks&quot;</span><span class="hl-1">;</span><br/><br/><span class="hl-4">const</span><span class="hl-1"> </span><span class="hl-5">doc</span><span class="hl-1"> = </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Document</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">sections:</span><span class="hl-1"> [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">headers:</span><span class="hl-1"> { </span><span class="hl-2">default:</span><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Header</span><span class="hl-1">({ </span><span class="hl-2">children:</span><span class="hl-1"> [</span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Paragraph</span><span class="hl-1">({ </span><span class="hl-2">children:</span><span class="hl-1"> [</span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">TextWatermark</span><span class="hl-1">({ </span><span class="hl-2">text:</span><span class="hl-1"> </span><span class="hl-3">&quot;DRAFT&quot;</span><span class="hl-1"> })] })] }) },</span><br/><span class="hl-1"> </span><span class="hl-2">children:</span><span class="hl-1"> [</span><br/><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Paragraph</span><span class="hl-1">({ </span><span class="hl-2">children:</span><span class="hl-1"> [</span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">ShapeRun</span><span class="hl-1">({ </span><span class="hl-2">type:</span><span class="hl-1"> </span><span class="hl-3">&quot;ellipse&quot;</span><span class="hl-1">, </span><span class="hl-2">transformation:</span><span class="hl-1"> { </span><span class="hl-2">width:</span><span class="hl-1"> </span><span class="hl-7">100</span><span class="hl-1">, </span><span class="hl-2">height:</span><span class="hl-1"> </span><span class="hl-7">60</span><span class="hl-1"> } })] }),</span><br/><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Paragraph</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">children:</span><span class="hl-1"> [</span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">ChartRun</span><span class="hl-1">({ </span><span class="hl-2">type:</span><span class="hl-1"> </span><span class="hl-3">&quot;column&quot;</span><span class="hl-1">, </span><span class="hl-2">categories:</span><span class="hl-1"> [</span><span class="hl-3">&quot;Q1&quot;</span><span class="hl-1">, </span><span class="hl-3">&quot;Q2&quot;</span><span class="hl-1">], </span><span class="hl-2">series:</span><span class="hl-1"> [{ </span><span class="hl-2">name:</span><span class="hl-1"> </span><span class="hl-3">&quot;Sales&quot;</span><span class="hl-1">, </span><span class="hl-2">values:</span><span class="hl-1"> [</span><span class="hl-7">10</span><span class="hl-1">, </span><span class="hl-7">20</span><span class="hl-1">] }] })],</span><br/><span class="hl-1"> }),</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>In a page without a bundler, load <code>dist/shapes.umd.cjs</code>, <code>dist/watermarks.umd.cjs</code> or <code>dist/charts.umd.cjs</code> after <code>dist/index.umd.cjs</code>. They add the <code>docxShapes</code>, <code>docxWatermarks</code> and <code>docxCharts</code> globals. See the <a href="https://docx.js.org/#/usage/shapes">shapes</a>, <a href="https://docx.js.org/#/usage/watermarks">watermarks</a> and <a href="https://docx.js.org/#/usage/charts">charts</a> documentation.</p>
<h1 id="html" class="tsd-anchor-link">HTML<a href="#html" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>HTML, such as what people write in a rich-text editor, becomes a document's paragraphs, lists, tables, images, links, equations and footnotes with <code>docx/html</code>, written in the document's own styles:</p>
<pre><code class="ts"><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">Document</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">htmlToContent</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/html&quot;</span><span class="hl-1">;</span><br/><br/><span class="hl-4">const</span><span class="hl-1"> </span><span class="hl-5">doc</span><span class="hl-1"> = </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Document</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">sections:</span><span class="hl-1"> [{ </span><span class="hl-2">children:</span><span class="hl-1"> </span><span class="hl-6">htmlToContent</span><span class="hl-1">(</span><span class="hl-3">&quot;&lt;h1&gt;Report&lt;/h1&gt;&lt;p&gt;Sales were &lt;b&gt;up 12%&lt;/b&gt;.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;EMEA&lt;/li&gt;&lt;li&gt;APAC&lt;/li&gt;&lt;/ul&gt;&quot;</span><span class="hl-1">) }],</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>In a page without a bundler, load <code>dist/html.umd.cjs</code> after <code>dist/index.umd.cjs</code> and <code>dist/math.umd.cjs</code>. It adds the <code>docxHtml</code> global. See the <a href="https://docx.js.org/#/usage/html">HTML</a> documentation.</p>
<h1 id="macros" class="tsd-anchor-link">Macros<a href="#macros" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>VBA macros, written from their code, make a document a macro-enabled document (<code>.docm</code>), with <code>docx/macros</code>:</p>
<pre><code class="ts"><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">Document</span><span class="hl-1">, </span><span class="hl-2">Paragraph</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">createMacros</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/macros&quot;</span><span class="hl-1">;</span><br/><br/><span class="hl-4">const</span><span class="hl-1"> </span><span class="hl-5">doc</span><span class="hl-1"> = </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Document</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">macros:</span><span class="hl-1"> </span><span class="hl-6">createMacros</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">modules:</span><span class="hl-1"> [{ </span><span class="hl-2">name:</span><span class="hl-1"> </span><span class="hl-3">&quot;Greetings&quot;</span><span class="hl-1">, </span><span class="hl-2">code:</span><span class="hl-1"> </span><span class="hl-3">&#39;Sub SayHello()</span><span class="hl-8">\n</span><span class="hl-3"> MsgBox &quot;Hello&quot;</span><span class="hl-8">\n</span><span class="hl-3">End Sub&#39;</span><span class="hl-1"> }],</span><br/><span class="hl-1"> }),</span><br/><span class="hl-1"> </span><span class="hl-2">sections:</span><span class="hl-1"> [{ </span><span class="hl-2">children:</span><span class="hl-1"> [</span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Paragraph</span><span class="hl-1">(</span><span class="hl-3">&quot;Run SayHello from View &gt; Macros&quot;</span><span class="hl-1">)] }],</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>In a page without a bundler, load <code>dist/macros.umd.cjs</code> after <code>dist/index.umd.cjs</code>. It adds the <code>docxMacros</code> global. See the <a href="https://docx.js.org/#/usage/macros">macros</a> documentation.</p>
<h1 id="embedded-files" class="tsd-anchor-link">Embedded Files<a href="#embedded-files" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Workbooks, documents, presentations and any other file, such as a sound, a video or a PDF, are embedded in a document as OLE objects, which open from it, with <code>docx/embedded-files</code>:</p>
<pre><code class="ts"><span class="hl-0">import</span><span class="hl-1"> </span><span class="hl-4">*</span><span class="hl-1"> </span><span class="hl-0">as</span><span class="hl-1"> </span><span class="hl-2">fs</span><span class="hl-1"> </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;fs&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">Document</span><span class="hl-1">, </span><span class="hl-2">Paragraph</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">EmbeddedFileRun</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/embedded-files&quot;</span><span class="hl-1">;</span><br/><br/><span class="hl-4">const</span><span class="hl-1"> </span><span class="hl-5">doc</span><span class="hl-1"> = </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Document</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">sections:</span><span class="hl-1"> [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">children:</span><span class="hl-1"> [</span><br/><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Paragraph</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">children:</span><span class="hl-1"> [</span><br/><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">EmbeddedFileRun</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">fileName:</span><span class="hl-1"> </span><span class="hl-3">&quot;budget.xlsx&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">data:</span><span class="hl-1"> </span><span class="hl-2">fs</span><span class="hl-1">.</span><span class="hl-6">readFileSync</span><span class="hl-1">(</span><span class="hl-3">&quot;./budget.xlsx&quot;</span><span class="hl-1">),</span><br/><span class="hl-1"> </span><span class="hl-2">preview:</span><span class="hl-1"> { </span><span class="hl-2">type:</span><span class="hl-1"> </span><span class="hl-3">&quot;png&quot;</span><span class="hl-1">, </span><span class="hl-2">data:</span><span class="hl-1"> </span><span class="hl-2">fs</span><span class="hl-1">.</span><span class="hl-6">readFileSync</span><span class="hl-1">(</span><span class="hl-3">&quot;./budget.png&quot;</span><span class="hl-1">) },</span><br/><span class="hl-1"> </span><span class="hl-2">transformation:</span><span class="hl-1"> { </span><span class="hl-2">width:</span><span class="hl-1"> </span><span class="hl-7">240</span><span class="hl-1">, </span><span class="hl-2">height:</span><span class="hl-1"> </span><span class="hl-7">120</span><span class="hl-1"> },</span><br/><span class="hl-1"> }),</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> }),</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>In a page without a bundler, load <code>dist/embedded-files.umd.cjs</code> after <code>dist/index.umd.cjs</code>. It adds the <code>docxEmbeddedFiles</code> global. See the <a href="https://docx.js.org/#/usage/embedded-files">embedded files</a> documentation.</p>
<h1 id="citations-and-bibliography" class="tsd-anchor-link">Citations and Bibliography<a href="#citations-and-bibliography" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Sources, citations of them in the text and a bibliography, in one of Word's styles of citation, such as APA, MLA or Chicago, written as Word writes them, with <code>docx/bibliography</code>:</p>
<pre><code class="ts"><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">Document</span><span class="hl-1">, </span><span class="hl-2">Paragraph</span><span class="hl-1">, </span><span class="hl-2">TextRun</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx&quot;</span><span class="hl-1">;</span><br/><span class="hl-0">import</span><span class="hl-1"> { </span><span class="hl-2">Bibliography</span><span class="hl-1">, </span><span class="hl-2">Citation</span><span class="hl-1">, </span><span class="hl-2">CitationStyle</span><span class="hl-1">, </span><span class="hl-2">SourceType</span><span class="hl-1">, </span><span class="hl-2">createBibliography</span><span class="hl-1"> } </span><span class="hl-0">from</span><span class="hl-1"> </span><span class="hl-3">&quot;docx/bibliography&quot;</span><span class="hl-1">;</span><br/><br/><span class="hl-4">const</span><span class="hl-1"> </span><span class="hl-5">doc</span><span class="hl-1"> = </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Document</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">bibliography:</span><span class="hl-1"> </span><span class="hl-6">createBibliography</span><span class="hl-1">({</span><br/><span class="hl-1"> </span><span class="hl-2">style:</span><span class="hl-1"> </span><span class="hl-2">CitationStyle</span><span class="hl-1">.</span><span class="hl-5">APA</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">sources:</span><span class="hl-1"> [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">tag:</span><span class="hl-1"> </span><span class="hl-3">&quot;Bak10&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">type:</span><span class="hl-1"> </span><span class="hl-2">SourceType</span><span class="hl-1">.</span><span class="hl-5">BOOK</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">authors:</span><span class="hl-1"> [{ </span><span class="hl-2">lastName:</span><span class="hl-1"> </span><span class="hl-3">&quot;Baker&quot;</span><span class="hl-1">, </span><span class="hl-2">firstName:</span><span class="hl-1"> </span><span class="hl-3">&quot;Anna&quot;</span><span class="hl-1"> }],</span><br/><span class="hl-1"> </span><span class="hl-2">title:</span><span class="hl-1"> </span><span class="hl-3">&quot;The Art of Pizza&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">year:</span><span class="hl-1"> </span><span class="hl-7">2010</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">city:</span><span class="hl-1"> </span><span class="hl-3">&quot;Naples&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-2">publisher:</span><span class="hl-1"> </span><span class="hl-3">&quot;Oven Press&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> }),</span><br/><span class="hl-1"> </span><span class="hl-2">sections:</span><span class="hl-1"> [</span><br/><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">children:</span><span class="hl-1"> [</span><br/><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Paragraph</span><span class="hl-1">({ </span><span class="hl-2">children:</span><span class="hl-1"> [</span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">TextRun</span><span class="hl-1">(</span><span class="hl-3">&quot;Pizza has been baked in Naples for centuries &quot;</span><span class="hl-1">), </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Citation</span><span class="hl-1">(</span><span class="hl-3">&quot;Bak10&quot;</span><span class="hl-1">)] }),</span><br/><span class="hl-1"> </span><span class="hl-4">new</span><span class="hl-1"> </span><span class="hl-6">Bibliography</span><span class="hl-1">({ </span><span class="hl-2">title:</span><span class="hl-1"> </span><span class="hl-3">&quot;References&quot;</span><span class="hl-1"> }),</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1"> },</span><br/><span class="hl-1"> ],</span><br/><span class="hl-1">});</span>
</code><button type="button">Copy</button></pre>
<p>In a page without a bundler, load <code>dist/bibliography.umd.cjs</code> after <code>dist/index.umd.cjs</code>. It adds the <code>docxBibliography</code> global. See the <a href="https://docx.js.org/#/usage/bibliography">citations and bibliography</a> documentation.</p>
<h1 id="playground" class="tsd-anchor-link">Playground<a href="#playground" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Experience <code>docx</code> in action through <a href="https://docxjs-editor.vercel.app/">Docx.js Editor</a>, an interactive playground where you can code and preview the results in real-time.</p>
<h1 id="examples" class="tsd-anchor-link">Examples<a href="#examples" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Check the <a href="https://github.com/dolanmiu/docx/tree/master/demo">demo folder</a> for examples.</p>
<h1 id="contributing" class="tsd-anchor-link">Contributing<a href="#contributing" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p>Read the contribution guidelines <a href="https://docx.js.org/#/contribution-guidelines">here</a>.</p>
<h1 id="used-by" class="tsd-anchor-link">Used by<a href="#used-by" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1>
<p><a href="https://hfour.com/"><img src="https://i.imgur.com/zy5qWmI.png" alt="drawing" height="50"/></a>
<a href="https://fuzzproductions.com/"><img src="https://i.imgur.com/OYP5tgS.png" alt="drawing" height="50"/></a>
<a href="https://www.mettzer.com/"><img src="https://i.imgur.com/zUDMfZ3.png" alt="drawing" height="50"/></a>
<a href="https://www.wisedoc.net/"><img src="https://i.imgur.com/wtNB1uq.png" alt="drawing" height="50"/></a>
<a href="https://www.dabblewriter.com/"><img src="https://i.imgur.com/suiH2zc.png" alt="drawing" height="50"/></a>
<a href="https://turbopatent.com/"><img src="https://i.imgur.com/1LjuK2M.png" alt="drawing" height="50"/></a>
<a href="http://www.madisoncres.com/"><img src="https://i.imgur.com/dHMg0wF.gif" alt="drawing" height="50"/></a>
<a href="https://www.beekast.com/"><img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/></a>
<a href="https://herraizsoto.com/"><img src="https://i.imgur.com/XVU6aoi.png" alt="drawing" height="50"/></a>
<a href="http://www.ativer.com.br/"><img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/></a>
<a href="https://www.arity.co/"><img src="https://i.imgur.com/cmykN7c.png" alt="drawing"/></a>
<a href="https://www.circadianrisk.com/"><img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/></a>
<a href="https://lexense.com/"><img src="https://i.imgur.com/AKGhtlh.png" alt="drawing"/></a>
<a href="https://novelpad.co/"><img src="https://i.imgur.com/9tqJaHw.png" alt="drawing" height="50"/></a>
<a href="https://proton.me/"><img src="https://i.imgur.com/5bLKFeP.png" alt="drawing" height="50"/></a></p>
<p>...and many more!</p>
<hr>
<p><a href="https://www.patreon.com/dolanmiu"><img src="https://user-images.githubusercontent.com/2917613/51251459-4e880480-1991-11e9-92bf-38b96675a9e2.png" alt="patreon"></a>
<a href="https://www.browserstack.com"><img src="https://user-images.githubusercontent.com/2917613/54233552-128e9d00-4505-11e9-88fb-025a4e04007c.png" alt="browserstack"></a></p>
<p>Made with 💖</p>
</div></div>
<div class="col-sidebar">
<div class="page-menu">
<div class="tsd-navigation settings">
<details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>
<h3>Settings</h3></summary>
<div class="tsd-accordion-details">
<div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span>
<ul id="tsd-filter-options">
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li>
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div>
<div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div>
<details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>
<h3>On This Page</h3></summary>
<div class="tsd-accordion-details"><a href="#demo"><span>Demo</span></a>
<ul>
<li><a href="#browser"><span>Browser</span></a></li>
<li><a href="#node"><span>Node</span></a></li></ul><a href="#how-to-use-documentation"><span>How to use &amp; <wbr/>Documentation</span></a><a href="#shapes-watermarks-and-charts"><span>Shapes, watermarks and charts</span></a><a href="#html"><span>HTML</span></a><a href="#macros"><span>Macros</span></a><a href="#embedded-files"><span>Embedded <wbr/>Files</span></a><a href="#citations-and-bibliography"><span>Citations and <wbr/>Bibliography</span></a><a href="#playground"><span>Playground</span></a><a href="#examples"><span>Examples</span></a><a href="#contributing"><span>Contributing</span></a><a href="#used-by"><span>Used by</span></a></div></details></div>
<div class="site-menu">
<nav class="tsd-navigation"><a href="modules.html">docx</a>
<ul class="tsd-small-nested-navigation" id="tsd-nav-container">
<li>Loading...</li></ul></nav></div></div></div><footer>
<p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer>
<div class="overlay"></div></body></html>