diff --git a/README.md b/README.md
index f9120883e0..cd876aa0a5 100644
--- a/README.md
+++ b/README.md
@@ -64,6 +64,12 @@ Check the `examples` section in the [documentation](https://docx.js.org/#/exampl
Read the contribution guidelines [here](https://docx.js.org/#/contribution-guidelines).
+# Used by
+
+[
](https://hfour.com/)
+[
](https://fuzzproductions.com/)
+[
](https://www.mettzer.com/)
+
---
Made with 💖
diff --git a/demo/demo10.ts b/demo/demo10.ts
index 84713e777f..5d207d5783 100644
--- a/demo/demo10.ts
+++ b/demo/demo10.ts
@@ -233,7 +233,7 @@ class DocumentCreator {
public createRoleText(roleText: string): Paragraph {
const paragraph = new Paragraph();
- const role = new TextRun(roleText).italic();
+ const role = new TextRun(roleText).italics();
paragraph.addRun(role);
diff --git a/demo/demo11.ts b/demo/demo11.ts
index 76ec915060..0253adb751 100644
--- a/demo/demo11.ts
+++ b/demo/demo11.ts
@@ -84,8 +84,7 @@ doc.Styles.createParagraphStyle("ListParagraph", "List Paragraph")
.basedOn("Normal");
doc.createImage(fs.readFileSync("./demo/images/pizza.gif"));
-doc
- .createParagraph("HEADING")
+doc.createParagraph("HEADING")
.heading1()
.center();
@@ -111,8 +110,8 @@ const table = new Table(4, 4);
table
.getRow(0)
.getCell(0)
- .addContent(new Paragraph("Pole No."));
-// table.Properties.width = 10000;
+ .addParagraph(new Paragraph("Pole No."));
+
doc.addTable(table);
const arrboth = [
@@ -129,8 +128,6 @@ const arrboth = [
arrboth.forEach((item) => {
const para = doc.createParagraph();
para.addImage(doc.createImage(fs.readFileSync(item.image)));
- // para.Properties.width = 60;
- // para.Properties.height = 90;
doc.createParagraph(item.comment).style("normalPara2");
});
diff --git a/demo/demo16.ts b/demo/demo16.ts
index 6c75218e53..9113a368b8 100644
--- a/demo/demo16.ts
+++ b/demo/demo16.ts
@@ -1,7 +1,7 @@
// Multiple sections and headers
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
-import { Document, Packer, PageNumberFormat, PageOrientation, Paragraph } from "../build";
+import { Document, Packer, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
const doc = new Document();
@@ -41,6 +41,40 @@ doc.addSection({
doc.createParagraph("hello in landscape");
+const header2 = doc.createHeader();
+const pageNumber = new TextRun("Page number: ").pageNumber();
+header2.createParagraph().addRun(pageNumber);
+
+doc.addSection({
+ headers: {
+ default: header2,
+ },
+ orientation: PageOrientation.PORTRAIT,
+});
+
+doc.createParagraph("Page number in the header must be 2, because it continues from the previous section.");
+
+doc.addSection({
+ headers: {
+ default: header2,
+ },
+ pageNumberFormatType: PageNumberFormat.UPPER_ROMAN,
+ orientation: PageOrientation.PORTRAIT,
+});
+
+doc.createParagraph("Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.");
+
+doc.addSection({
+ headers: {
+ default: header2,
+ },
+ pageNumberFormatType: PageNumberFormat.DECIMAL,
+ pageNumberStart: 25,
+ orientation: PageOrientation.PORTRAIT,
+});
+
+doc.createParagraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section.");
+
const packer = new Packer();
packer.toBuffer(doc).then((buffer) => {
diff --git a/demo/demo20.ts b/demo/demo20.ts
index f3f43edb26..c0158d8dce 100644
--- a/demo/demo20.ts
+++ b/demo/demo20.ts
@@ -8,8 +8,8 @@ const doc = new Document();
const table = doc.createTable(4, 4);
table
.getCell(2, 2)
- .addContent(new Paragraph("Hello"))
- .CellProperties.Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red")
+ .addParagraph(new Paragraph("Hello"))
+ .Borders.addTopBorder(BorderStyle.DASH_DOT_STROKED, 3, "red")
.addBottomBorder(BorderStyle.DOUBLE, 3, "blue")
.addStartBorder(BorderStyle.DOT_DOT_DASH, 3, "green")
.addEndBorder(BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
diff --git a/demo/demo22.ts b/demo/demo22.ts
index c5051ab019..6f5baa970c 100644
--- a/demo/demo22.ts
+++ b/demo/demo22.ts
@@ -16,7 +16,7 @@ paragraph2.addRun(textRun2);
doc.addParagraph(paragraph2);
const paragraph3 = new Paragraph().bidirectional();
-const textRun3 = new TextRun("שלום עולם").italic().rightToLeft();
+const textRun3 = new TextRun("שלום עולם").italics().rightToLeft();
paragraph3.addRun(textRun3);
doc.addParagraph(paragraph3);
diff --git a/demo/demo24.ts b/demo/demo24.ts
index 4901477ced..62d80592a4 100644
--- a/demo/demo24.ts
+++ b/demo/demo24.ts
@@ -6,10 +6,10 @@ import { Document, Media, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(4, 4);
-table.getCell(2, 2).addContent(new Paragraph("Hello"));
+table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
-table.getCell(1, 1).addContent(image.Paragraph);
+table.getCell(1, 1).addParagraph(image.Paragraph);
const packer = new Packer();
diff --git a/demo/demo31.ts b/demo/demo31.ts
index 366227102a..349dd7e393 100644
--- a/demo/demo31.ts
+++ b/demo/demo31.ts
@@ -8,12 +8,12 @@ const doc = new Document();
const table = doc.createTable(2, 2);
table
.getCell(1, 1)
- .addContent(new Paragraph("This text should be in the middle of the cell"))
- .CellProperties.setVerticalAlign(VerticalAlign.CENTER);
+ .addParagraph(new Paragraph("This text should be in the middle of the cell"))
+ .setVerticalAlign(VerticalAlign.CENTER);
table
.getCell(1, 0)
- .addContent(
+ .addParagraph(
new Paragraph(
"Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah",
).heading1(),
diff --git a/demo/demo32.ts b/demo/demo32.ts
index 373ca64266..67c9e8a335 100644
--- a/demo/demo32.ts
+++ b/demo/demo32.ts
@@ -1,4 +1,4 @@
-// Example of how you would create a table and add data to it
+// Example of how you would merge cells together
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, Packer, Paragraph } from "../build";
@@ -7,24 +7,24 @@ const doc = new Document();
let table = doc.createTable(2, 2);
-table.getCell(0, 0).addContent(new Paragraph("Hello"));
+table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
table.getRow(0).mergeCells(0, 1);
doc.createParagraph("Another table").heading2();
table = doc.createTable(2, 3);
-table.getCell(0, 0).addContent(new Paragraph("World"));
+table.getCell(0, 0).addParagraph(new Paragraph("World"));
table.getRow(0).mergeCells(0, 2);
doc.createParagraph("Another table").heading2();
table = doc.createTable(2, 4);
-table.getCell(0, 0).addContent(new Paragraph("Foo"));
+table.getCell(0, 0).addParagraph(new Paragraph("Foo"));
-table.getCell(1, 0).addContent(new Paragraph("Bar1"));
-table.getCell(1, 1).addContent(new Paragraph("Bar2"));
-table.getCell(1, 2).addContent(new Paragraph("Bar3"));
-table.getCell(1, 3).addContent(new Paragraph("Bar4"));
+table.getCell(1, 0).addParagraph(new Paragraph("Bar1"));
+table.getCell(1, 1).addParagraph(new Paragraph("Bar2"));
+table.getCell(1, 2).addParagraph(new Paragraph("Bar3"));
+table.getCell(1, 3).addParagraph(new Paragraph("Bar4"));
table.getRow(0).mergeCells(0, 3);
diff --git a/demo/demo34.ts b/demo/demo34.ts
index 098e1c2065..2a46308394 100644
--- a/demo/demo34.ts
+++ b/demo/demo34.ts
@@ -20,9 +20,9 @@ const table = doc.createTable(2, 2).float({
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
});
table.setFixedWidthLayout();
-table.setWidth(WidthType.DXA, 4535);
+table.setWidth(4535, WidthType.DXA);
-table.getCell(0, 0).addContent(new Paragraph("Hello"));
+table.getCell(0, 0).addParagraph(new Paragraph("Hello"));
table.getRow(0).mergeCells(0, 1);
const packer = new Packer();
diff --git a/demo/demo35.ts b/demo/demo35.ts
new file mode 100644
index 0000000000..a91ad2347d
--- /dev/null
+++ b/demo/demo35.ts
@@ -0,0 +1,17 @@
+// Simple example to add text to a document
+// Import from 'docx' rather than '../build' if you install from npm
+import * as fs from "fs";
+import { Document, Packer, Paragraph, TextRun } from "../build";
+
+var doc = new Document();
+var paragraph = new Paragraph();
+var link = doc.createHyperlink('http://www.example.com', 'Hyperlink');
+link.bold();
+paragraph.addHyperLink(link);
+doc.addParagraph(paragraph);
+
+const packer = new Packer();
+
+packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docx", buffer);
+});
diff --git a/demo/demo36.ts b/demo/demo36.ts
new file mode 100644
index 0000000000..e9db47f25c
--- /dev/null
+++ b/demo/demo36.ts
@@ -0,0 +1,23 @@
+// Add images to header and footer
+// Import from 'docx' rather than '../build' if you install from npm
+import * as fs from "fs";
+import { Document, Media, Packer, Table } from "../build";
+
+const doc = new Document();
+const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
+
+const table = new Table(2, 2);
+table.getCell(1, 1).addContent(image.Paragraph);
+
+// doc.createParagraph("Hello World");
+doc.addTable(table);
+
+// doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));
+doc.Header.addTable(table);
+// doc.Footer.createImage(fs.readFileSync("./demo/images/pizza.gif"));
+
+const packer = new Packer();
+
+packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docx", buffer);
+});
diff --git a/demo/demo37.ts b/demo/demo37.ts
new file mode 100644
index 0000000000..0aaf380d51
--- /dev/null
+++ b/demo/demo37.ts
@@ -0,0 +1,18 @@
+// Add images to header and footer
+// Import from 'docx' rather than '../build' if you install from npm
+import * as fs from "fs";
+import { Document, Media, Packer } from "../build";
+
+const doc = new Document();
+const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
+doc.createParagraph("Hello World");
+
+doc.Header.addImage(image);
+doc.Header.createImage(fs.readFileSync("./demo/images/pizza.gif"));
+doc.Header.createImage(fs.readFileSync("./demo/images/image1.jpeg"));
+
+const packer = new Packer();
+
+packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My Document.docx", buffer);
+});
diff --git a/demo/demo4.ts b/demo/demo4.ts
index eb6f5b8c09..87c3f418e6 100644
--- a/demo/demo4.ts
+++ b/demo/demo4.ts
@@ -6,7 +6,7 @@ import { Document, Packer, Paragraph } from "../build";
const doc = new Document();
const table = doc.createTable(4, 4);
-table.getCell(2, 2).addContent(new Paragraph("Hello"));
+table.getCell(2, 2).addParagraph(new Paragraph("Hello"));
const packer = new Packer();
diff --git a/docs/README.md b/docs/README.md
index 4fc5757477..fd5ad9ecd9 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -29,6 +29,7 @@ import * as docx from "docx";
## Basic Usage
```js
+var fs = require("fs");
var docx = require("docx");
// Create document
@@ -41,11 +42,12 @@ paragraph.addRun(new docx.TextRun("Lorem Ipsum Foo Bar"));
doc.addParagraph(paragraph);
// Used to export the file into a .docx file
-var exporter = new docx.LocalPacker(doc);
+var packer = new docx.Packer();
+packer.toBuffer(doc).then((buffer) => {
+ fs.writeFileSync("My First Document.docx", buffer);
+});
-exporter.pack("My First Document");
-
-// Done! A file called 'My First Document.docx' will be in your file system if you used LocalPacker
+// Done! A file called 'My First Document.docx' will be in your file system.
```
## Honoured Mentions
diff --git a/docs/contribution-guidelines.md b/docs/contribution-guidelines.md
index 9bc1d4c90d..89f2f2b900 100644
--- a/docs/contribution-guidelines.md
+++ b/docs/contribution-guidelines.md
@@ -12,7 +12,7 @@
## Always think about the user
-The number one pillar for contribution is to **ALWAYS** think about how the user will use the library.
+The number one pillar for contribution to `docx` is to **ALWAYS** think about how the user will use `docx`.
Put yourself in their position, and imagine how they would feel about your feature you wrote.
@@ -37,13 +37,13 @@ Unesesary coment removed // Make sure to use correct spelling
## No leaky components in API interface
-This mainly applies to the API the end user will consume.
+> This mainly applies to the API the end user will consume.
-Try to make method parameters accept primatives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
+Try to make method parameters of the outside API accept primatives, or `json` objects, so that child components are created **inside** the component, rather than being **injected** in.
This is so that:
-1. Imports are much cleaner, no need for:
+1. Imports are much cleaner for the end user, no need for:
```js
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
```
@@ -52,13 +52,17 @@ This is so that:
3. It means the end user does not need to import and create the child component to be injected.
**Do not**
-`TableFloatProperties` is a class. The outside world would have to construct the object, and inject it in
+
+`TableFloatProperties` is a class. The outside world would have to `new` up the object, and inject it in like so:
+
```js
public float(tableFloatProperties: TableFloatProperties): Table
```
**Do**
-`ITableFloatOptions` is an interface for a JSON of primatives.
+
+`ITableFloatOptions` is an interface for a JSON of primatives. The end user would need to pass in a json object and not need to worry about the internals:
+
```js
public float(tableFloatOptions: ITableFloatOptions): Table
```
@@ -76,7 +80,8 @@ This is just a guideline, and the rules can sometimes be broken.
}
```
-* Use `add` if you add the element into the method as a parameter:
+* Use `add` if you add the element into the method as a parameter.
+ *Note:* This may look like its breaking the previous guideline, but it has semantically different meanings. The previous one is using data to construct an object, whereas this one is simply adding elements into the document:
```js
public addParagraph(paragraph: Paragraph) {
diff --git a/docs/examples.md b/docs/examples.md
index 05dbfb2de5..5964aecafe 100644
--- a/docs/examples.md
+++ b/docs/examples.md
@@ -158,7 +158,8 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.ts_
## Sections
-Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document
+Example of how sections work. Sections allow multiple headers and footers, and `landscape`/`portrait` inside the same document.
+Also you can have different page number formats and starts for different sections.
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo16.ts ":include")
diff --git a/docs/index.html b/docs/index.html
index 4b35f622af..9af955e10e 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -25,6 +25,7 @@
+