Compare commits
372 Commits
Author | SHA1 | Date | |
---|---|---|---|
9cf7f3cf54 | |||
77afb55167 | |||
e86997576f | |||
a67e306737 | |||
48ea634e08 | |||
ea29f515b0 | |||
41d27cb78c | |||
ff45c182ce | |||
0519ed6d09 | |||
f41e19c251 | |||
329a70c312 | |||
419fef5759 | |||
3299c557a0 | |||
4783812044 | |||
6e21cdbf17 | |||
caf188caae | |||
c8db70b3b7 | |||
eb0479d80b | |||
181d56ca80 | |||
b1d1b9e9b7 | |||
28685a8761 | |||
ecd1596682 | |||
6746f81da5 | |||
c7075d740f | |||
0faac01f6b | |||
bdfaee2cb3 | |||
131183ae19 | |||
8b2aa58198 | |||
4fe2973473 | |||
93ec9eed7a | |||
ba5cb1483b | |||
1436f4d4b2 | |||
107e6ce1d9 | |||
2d5e08588c | |||
24f95aee8b | |||
c5e9e3b2a0 | |||
0b85e07701 | |||
40b3bc0b90 | |||
bd40b11ce4 | |||
a3febae8a3 | |||
18ce200cdb | |||
cc32a7b2d3 | |||
e7eca14e1e | |||
7f86385b09 | |||
2fa8df7cf4 | |||
f0e50dd21f | |||
0bc36d924f | |||
4bc0421055 | |||
cc9a966f53 | |||
8aa804db18 | |||
b3ffa60f14 | |||
8724fbe7a7 | |||
2391375ac0 | |||
12817957f4 | |||
58f7e5a9a3 | |||
0b88cb0ca5 | |||
dbaa493ebd | |||
4b5d2d98f9 | |||
9864cdea16 | |||
566ac03f9a | |||
cf6c4998d0 | |||
0891e2a8c3 | |||
48d9e75707 | |||
cd501bba0a | |||
57f80e636e | |||
89c2e14979 | |||
8c2ba7a452 | |||
cd232496e2 | |||
0cdb1a9286 | |||
7ebef8b3b5 | |||
e98fe5921c | |||
98253c3445 | |||
9bda9e8375 | |||
bf4498061a | |||
13d0f33af6 | |||
d4bc89d141 | |||
0c42298dce | |||
f997515af4 | |||
624afb8fba | |||
71f8bcffe7 | |||
e8bdeed63f | |||
2b7ca92ade | |||
fdf0764245 | |||
993782129c | |||
65302dd39b | |||
a0d8911e18 | |||
2d4a452d2e | |||
3f2ad04d65 | |||
283c42cb55 | |||
0ec3b64ad7 | |||
b972f1789e | |||
90495d08a6 | |||
5fc28cb67d | |||
bb6abe5e09 | |||
d1a8f983d3 | |||
e169e01002 | |||
e5da573041 | |||
9557015c6c | |||
512d81649f | |||
fc1e0dad3f | |||
ec22720244 | |||
9743dfa8cc | |||
805bd94a25 | |||
c3faf3bbd8 | |||
5b3427cada | |||
df7a90d3c1 | |||
f3f65da207 | |||
9326a0a998 | |||
909a86df7f | |||
a5da9f44e8 | |||
2f732e7378 | |||
31269c85d2 | |||
95556e57df | |||
2aa93e6105 | |||
a026e5bd1f | |||
9327f2bfa1 | |||
603dd36458 | |||
53ababf3a7 | |||
3e58910bfc | |||
736ca6a46d | |||
f90e84a88d | |||
a79b1e36dc | |||
dd503996a0 | |||
694ac22dad | |||
8435ece00d | |||
cdd22efd79 | |||
c6e9696be0 | |||
655b40d418 | |||
60664a2a83 | |||
e750735fa4 | |||
0de7116b78 | |||
45b1f6f9a3 | |||
4159be5644 | |||
10455a534f | |||
84f48446df | |||
32ceaa415e | |||
5e06d73f45 | |||
bfd0f0c7bb | |||
858a994d13 | |||
bb2f77aa67 | |||
48c1559a77 | |||
a6f77d01ca | |||
4dafa62e17 | |||
49314ea9d0 | |||
acaaf98e20 | |||
0e2bfe9e3f | |||
d6f363b275 | |||
118ea57412 | |||
7c8be4c8a7 | |||
fa9021596f | |||
3ccf4bdfe3 | |||
f2480673ec | |||
e93b8032d8 | |||
5de2d8c7fb | |||
e355fd3d2e | |||
d41ef99c85 | |||
5ec18d6e01 | |||
b4cd3a319c | |||
d894bfa167 | |||
d74db948ba | |||
3ef26c747b | |||
38c8220e9e | |||
86f8259b33 | |||
502db14bba | |||
ef12ada5d7 | |||
977b2b302d | |||
17d02a3d1c | |||
6100ff4c4e | |||
8bb73fb25e | |||
d6cce4ae15 | |||
058304d16b | |||
345d34a2e1 | |||
3839a49d47 | |||
0afe0929a3 | |||
a14a1fbd10 | |||
52f0a6958a | |||
8bdde98db1 | |||
19fc900045 | |||
6bdd9b882a | |||
0d97d428fa | |||
a0b42d7bdb | |||
69ba312a96 | |||
a0c13214e6 | |||
4c8829df28 | |||
3ee3e95410 | |||
806deeaf78 | |||
feb121707d | |||
31c7f034ec | |||
30ab92652c | |||
0407548113 | |||
277845626c | |||
b2af8b970e | |||
542866e18b | |||
f54192809f | |||
f3ba62fd88 | |||
8d4a07302b | |||
d504231124 | |||
173b1e118c | |||
ffba276f0d | |||
b210608e56 | |||
74353104dc | |||
825136d1c9 | |||
b2fea471f1 | |||
e9adb8b0ed | |||
5d6bc039d0 | |||
27638063c8 | |||
f6a4d78ab7 | |||
4061e31400 | |||
74db67689f | |||
2213eb28cb | |||
d1b45d416b | |||
f72f7e7514 | |||
0165cfb3e5 | |||
ef747486c0 | |||
e0b2f59c2f | |||
82bdb301f9 | |||
c7ea26e422 | |||
34b2029efe | |||
37e610d2b3 | |||
4882235d20 | |||
1552ebde11 | |||
d263d0c8a5 | |||
610b2388bb | |||
bcb16cef9b | |||
0f3afd94f3 | |||
60eb686d05 | |||
7f5e43fba9 | |||
ed52ef358b | |||
214afab711 | |||
18a1677588 | |||
cae372e9ad | |||
ea5f9a48ab | |||
dcf755e756 | |||
d445c21ea1 | |||
6db0449ed0 | |||
ae37b1980f | |||
96f76906c4 | |||
19d9619785 | |||
5be195fd91 | |||
e36e9e1cf4 | |||
102d6aa55c | |||
daea8d2868 | |||
700a74fd4c | |||
32a84a5ad0 | |||
3c9f9474ce | |||
1e10686315 | |||
cae6405d9a | |||
a884ce94e5 | |||
065c17de74 | |||
09db2c528a | |||
2adfe532dd | |||
6cbe40cecb | |||
6b9467393e | |||
5125e77431 | |||
ab68ae0092 | |||
38079b6171 | |||
d584290f3d | |||
9b9baa9b4a | |||
c258310560 | |||
af0bf5ced5 | |||
57c480a6c6 | |||
25f7423533 | |||
0c068bb03b | |||
1822473abc | |||
93a7d607b2 | |||
d45213636c | |||
e196d9d917 | |||
cf88e50afd | |||
64e5814c31 | |||
37251c84f8 | |||
a576098639 | |||
2450fe83ce | |||
e1004440d2 | |||
491c7abd1c | |||
364ce6d856 | |||
ffb6b73bb7 | |||
6041c39a26 | |||
c54f0a52f6 | |||
6b87d9c038 | |||
1285304f97 | |||
58fae6b201 | |||
dc1f3aebe9 | |||
8a189161f2 | |||
6667595627 | |||
33befaab09 | |||
c91f135c28 | |||
08f9926e60 | |||
f323b293fb | |||
adc91929b0 | |||
c63cba5a0c | |||
e65e7d6a32 | |||
7a48da440b | |||
05dda37b71 | |||
fc87a73259 | |||
ec4c4fb5c4 | |||
ee43585210 | |||
870c222dd5 | |||
a6eb8e01df | |||
8c45c30753 | |||
d18cfbc26f | |||
f4af5f9e33 | |||
69adbbc1c1 | |||
4f6a9f734c | |||
8b78f2d200 | |||
26a3fa6946 | |||
f955a18936 | |||
ee1a7818b6 | |||
8e455f1097 | |||
827c46cf47 | |||
61cbee829d | |||
f0ad1e9194 | |||
bbd339f0e4 | |||
858af64dc3 | |||
01e34c1b28 | |||
41acb475a9 | |||
20978f8c24 | |||
265a3dbe21 | |||
627f5b4bf0 | |||
1538c1aaeb | |||
839661e5f8 | |||
fff6244597 | |||
b2280f64a1 | |||
21d53c41d0 | |||
6e94bbb5e5 | |||
7d655cd3f7 | |||
00821677c8 | |||
784de3e430 | |||
3213c4838d | |||
1b9bc8eb1d | |||
bf58d0b864 | |||
28ca8392ed | |||
5238c55bc2 | |||
901f10c387 | |||
defa22ffe5 | |||
84919c0cc0 | |||
1e8ca123b0 | |||
3ae7c6aedf | |||
6a3ed4bbf8 | |||
e632d323c9 | |||
d2b35ab8f2 | |||
e60f39df41 | |||
076431e04d | |||
75ab44403c | |||
e2d6097819 | |||
ab12ff1257 | |||
25a0212f4e | |||
a8993f14d6 | |||
1834cd86da | |||
437de27ed8 | |||
96f08482da | |||
edec2eca7a | |||
9202524d83 | |||
0461907533 | |||
6b3d1d5579 | |||
445a2896d2 | |||
e2d8f1b6b1 | |||
7baa696a76 | |||
3f7ca6bbff | |||
36e1c5fe6a | |||
75a03f1576 | |||
437e83ab78 | |||
5bca7d155f | |||
db7c4da609 | |||
9c11653313 | |||
9aab68a8f8 | |||
2100b7b7d2 | |||
2cf1cce06d | |||
4ca44d335d | |||
358d578cd7 | |||
c61d24d8d4 | |||
4f8d435e16 | |||
a1b9be453b |
@ -7,6 +7,7 @@ indent_style = space
|
|||||||
indent_size = 4
|
indent_size = 4
|
||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
max_line_length = off
|
max_line_length = off
|
||||||
|
9
.github/ISSUE_TEMPLATE.md
vendored
Normal file
9
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
# Thank you for raising an issue to `docx`
|
||||||
|
|
||||||
|
Please do not raise an issue unless it is an **issue**.
|
||||||
|
|
||||||
|
- Is your issue a feature request? Are you giving ideas to the community? Are you asking for help? Please raise a ticket in the `Discussions` section:
|
||||||
|
|
||||||
|
https://github.com/dolanmiu/docx/discussions
|
||||||
|
|
||||||
|
- Is your issue a previously asked? Please respond to that thread instead
|
134
.github/workflows/default.yml
vendored
Normal file
134
.github/workflows/default.yml
vendored
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
name: Default
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
- name: Archive Production Artifact
|
||||||
|
uses: actions/upload-artifact@master
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Test
|
||||||
|
run: npm run test.coverage
|
||||||
|
lint:
|
||||||
|
name: Lint
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
prettier:
|
||||||
|
name: Prettier
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Prettier
|
||||||
|
run: npm run style
|
||||||
|
demos:
|
||||||
|
name: Run Demos
|
||||||
|
needs: [build]
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Repo
|
||||||
|
uses: actions/checkout@master
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
- name: Download Artifact
|
||||||
|
uses: actions/download-artifact@master
|
||||||
|
with:
|
||||||
|
name: build
|
||||||
|
path: build
|
||||||
|
- name: Run demos
|
||||||
|
run: |
|
||||||
|
npm run ts-node -- ./demo/1-basic.ts
|
||||||
|
npm run ts-node -- ./demo/2-declaritive-styles.ts
|
||||||
|
npm run ts-node -- ./demo/3-numbering-and-bullet-points.ts
|
||||||
|
npm run ts-node -- ./demo/4-basic-table.ts
|
||||||
|
npm run ts-node -- ./demo/5-images.ts
|
||||||
|
npm run ts-node -- ./demo/6-page-borders.ts
|
||||||
|
npm run ts-node -- ./demo/7-landscape.ts
|
||||||
|
npm run ts-node -- ./demo/8-header-footer.ts
|
||||||
|
npm run ts-node -- ./demo/9-images-in-header-and-footer.ts
|
||||||
|
npm run ts-node -- ./demo/10-my-cv.ts
|
||||||
|
npm run ts-node -- ./demo/11-declaritive-styles-2.ts
|
||||||
|
npm run ts-node -- ./demo/12-scaling-images.ts
|
||||||
|
npm run ts-node -- ./demo/13-xml-styles.ts
|
||||||
|
npm run ts-node -- ./demo/14-page-numbers.ts
|
||||||
|
npm run ts-node -- ./demo/15-page-break-before.ts
|
||||||
|
npm run ts-node -- ./demo/16-multiple-sections.ts
|
||||||
|
npm run ts-node -- ./demo/17-footnotes.ts
|
||||||
|
npm run ts-node -- ./demo/18-image-from-buffer.ts
|
||||||
|
npm run ts-node -- ./demo/19-export-to-base64.ts
|
||||||
|
npm run ts-node -- ./demo/20-table-cell-borders.ts
|
||||||
|
npm run ts-node -- ./demo/21-bookmarks.ts
|
||||||
|
npm run ts-node -- ./demo/22-right-to-left-text.ts
|
||||||
|
npm run ts-node -- ./demo/23-base64-images.ts
|
||||||
|
npm run ts-node -- ./demo/24-images-to-table-cell.ts
|
||||||
|
npm run ts-node -- ./demo/25-table-xml-styles.ts
|
||||||
|
npm run ts-node -- ./demo/26-paragraph-borders.ts
|
||||||
|
npm run ts-node -- ./demo/27-declaritive-styles-3.ts
|
||||||
|
npm run ts-node -- ./demo/28-table-of-contents.ts
|
||||||
|
npm run ts-node -- ./demo/29-numbered-lists.ts
|
||||||
|
npm run ts-node -- ./demo/30-template-document.ts
|
||||||
|
npm run ts-node -- ./demo/31-tables.ts
|
||||||
|
npm run ts-node -- ./demo/32-merge-and-shade-table-cells.ts
|
||||||
|
npm run ts-node -- ./demo/33-sequential-captions.ts
|
||||||
|
npm run ts-node -- ./demo/34-floating-tables.ts
|
||||||
|
npm run ts-node -- ./demo/35-hyperlinks.ts
|
||||||
|
npm run ts-node -- ./demo/36-image-to-table-cell.ts
|
||||||
|
npm run ts-node -- ./demo/37-images-to-header-and-footer.ts
|
||||||
|
npm run ts-node -- ./demo/38-text-wrapping.ts
|
||||||
|
npm run ts-node -- ./demo/39-page-numbers.ts
|
||||||
|
npm run ts-node -- ./demo/40-line-numbers.ts
|
||||||
|
npm run ts-node -- ./demo/41-merge-table-cells-2.ts
|
||||||
|
npm run ts-node -- ./demo/42-restart-page-numbers.ts
|
||||||
|
npm run ts-node -- ./demo/43-images-to-table-cell-2.ts
|
||||||
|
npm run ts-node -- ./demo/44-multiple-columns.ts
|
||||||
|
npm run ts-node -- ./demo/45-highlighting-text.ts
|
||||||
|
npm run ts-node -- ./demo/46-shading-text.ts
|
||||||
|
npm run ts-node -- ./demo/47-number-of-total-pages-section.ts
|
||||||
|
npm run ts-node -- ./demo/48-vertical-align.ts
|
||||||
|
npm run ts-node -- ./demo/49-table-borders.ts
|
||||||
|
npm run ts-node -- ./demo/50-readme-demo.ts
|
||||||
|
npm run ts-node -- ./demo/51-character-styles.ts
|
||||||
|
npm run ts-node -- ./demo/52-japanese.ts
|
||||||
|
npm run ts-node -- ./demo/53-chinese.ts
|
||||||
|
npm run ts-node -- ./demo/54-custom-properties.ts
|
||||||
|
npm run ts-node -- ./demo/55-math.ts
|
||||||
|
npm run ts-node -- ./demo/56-background-color.ts
|
||||||
|
npm run ts-node -- ./demo/57-add-parent-numbered-lists.ts
|
||||||
|
npm run ts-node -- ./demo/58-section-types.ts
|
||||||
|
npm run ts-node -- ./demo/59-header-footer-margins.ts
|
||||||
|
npm run ts-node -- ./demo/60-track-revisions.ts
|
||||||
|
npm run ts-node -- ./demo/61-text-frame.ts
|
||||||
|
npm run ts-node -- ./demo/62-paragraph-spacing.ts
|
||||||
|
npm run ts-node -- ./demo/63-odd-even-header-footer.ts
|
11
.nycrc
11
.nycrc
@ -1,14 +1,15 @@
|
|||||||
{
|
{
|
||||||
"check-coverage": true,
|
"check-coverage": true,
|
||||||
"lines": 93.53,
|
"lines": 98.86,
|
||||||
"functions": 89.63,
|
"functions": 97.86,
|
||||||
"branches": 88.57,
|
"branches": 95.86,
|
||||||
"statements": 93.34,
|
"statements": 98.86,
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*.ts"
|
"src/**/*.ts"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"src/**/*.spec.ts"
|
"src/**/*.spec.ts",
|
||||||
|
"src/import-dotx/import-dotx.ts"
|
||||||
],
|
],
|
||||||
"reporter": [
|
"reporter": [
|
||||||
"lcov",
|
"lcov",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- 9
|
- 10
|
||||||
install:
|
install:
|
||||||
- npm install
|
- npm install
|
||||||
- npm install -g codecov
|
- npm install -g codecov
|
||||||
|
24
README.md
24
README.md
@ -11,6 +11,7 @@
|
|||||||
[![NPM version][npm-image]][npm-url]
|
[![NPM version][npm-image]][npm-url]
|
||||||
[![Downloads per month][downloads-image]][downloads-url]
|
[![Downloads per month][downloads-image]][downloads-url]
|
||||||
[![Build Status][travis-image]][travis-url]
|
[![Build Status][travis-image]][travis-url]
|
||||||
|
[![GitHub Action Workflow Status][github-actions-workflow-image]][github-actions-workflow-url]
|
||||||
[![Dependency Status][daviddm-image]][daviddm-url]
|
[![Dependency Status][daviddm-image]][daviddm-url]
|
||||||
[![Known Vulnerabilities][snky-image]][snky-url]
|
[![Known Vulnerabilities][snky-image]][snky-url]
|
||||||
[![Chat on Gitter][gitter-image]][gitter-url]
|
[![Chat on Gitter][gitter-image]][gitter-url]
|
||||||
@ -18,7 +19,7 @@
|
|||||||
[![codecov][codecov-image]][codecov-url]
|
[![codecov][codecov-image]][codecov-url]
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://i.imgur.com/TCH0YzD.png" alt="drawing" width="800"/>
|
<img src="https://i.imgur.com/tBO0XBR.png" alt="drawing"/>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
# Demo
|
# Demo
|
||||||
@ -32,7 +33,16 @@ Here are examples of `docx` being used with basic `HTML/JS` in a browser environ
|
|||||||
|
|
||||||
Here is an example of `docx` working in `Angular`:
|
Here is an example of `docx` working in `Angular`:
|
||||||
|
|
||||||
* https://stackblitz.com/edit/angular-afvxtz
|
* https://stackblitz.com/edit/angular-docx
|
||||||
|
|
||||||
|
Here is an example of `docx` working in `React`:
|
||||||
|
|
||||||
|
* https://stackblitz.com/edit/react-docx
|
||||||
|
* https://stackblitz.com/edit/react-docx-images (adding images to Word Document)
|
||||||
|
|
||||||
|
Here is an example of `docx` working in `Vue.js`:
|
||||||
|
|
||||||
|
* https://stackblitz.com/edit/vuejs-docx
|
||||||
|
|
||||||
## Node
|
## Node
|
||||||
|
|
||||||
@ -50,7 +60,7 @@ Press `endpoint` on the `RunKit` website:
|
|||||||
* https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
* https://runkit.com/dolanmiu/docx-demo8 - Header and Footer
|
||||||
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
* https://runkit.com/dolanmiu/docx-demo10 - **My CV generated with docx**
|
||||||
|
|
||||||
More [here](https://docx.js.org/#/examples) and [here](https://github.com/dolanmiu/docx/tree/master/demo)
|
More [here](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||||
|
|
||||||
# How to use & Documentation
|
# How to use & Documentation
|
||||||
|
|
||||||
@ -58,7 +68,7 @@ Please refer to the [documentation at https://docx.js.org/](https://docx.js.org/
|
|||||||
|
|
||||||
# Examples
|
# Examples
|
||||||
|
|
||||||
Check the `examples` section in the [documentation](https://docx.js.org/#/examples) and the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
|
Check the [demo folder](https://github.com/dolanmiu/docx/tree/master/demo) for examples.
|
||||||
|
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
@ -74,8 +84,10 @@ Read the contribution guidelines [here](https://docx.js.org/#/contribution-guide
|
|||||||
[<img src="https://i.imgur.com/1LjuK2M.png" alt="drawing" height="50"/>](https://turbopatent.com/)
|
[<img src="https://i.imgur.com/1LjuK2M.png" alt="drawing" height="50"/>](https://turbopatent.com/)
|
||||||
[<img src="https://i.imgur.com/dHMg0wF.gif" alt="drawing" height="50"/>](http://www.madisoncres.com/)
|
[<img src="https://i.imgur.com/dHMg0wF.gif" alt="drawing" height="50"/>](http://www.madisoncres.com/)
|
||||||
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
[<img src="https://i.imgur.com/QEZXU5b.png" alt="drawing" height="50"/>](https://www.beekast.com/)
|
||||||
[<img src="https://imgur.com/XVU6aoi.png" alt="drawing" height="50"/>](https://herraizsoto.com/)
|
[<img src="https://i.imgur.com/XVU6aoi.png" alt="drawing" height="50"/>](https://herraizsoto.com/)
|
||||||
[<img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/>](http://www.ativer.com.br/)
|
[<img src="https://i.imgur.com/fn1xccG.png" alt="drawing" height="50"/>](http://www.ativer.com.br/)
|
||||||
|
[<img src="https://i.imgur.com/cmykN7c.png" alt="drawing" />](https://www.arity.co/)
|
||||||
|
[<img src="https://i.imgur.com/PXo25um.png" alt="drawing" height="50"/>](https://www.circadianrisk.com/)
|
||||||
|
|
||||||
|
|
||||||
...and many more!
|
...and many more!
|
||||||
@ -93,6 +105,8 @@ Made with 💖
|
|||||||
[downloads-url]: https://npmjs.org/package/docx
|
[downloads-url]: https://npmjs.org/package/docx
|
||||||
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
|
[travis-image]: https://travis-ci.org/dolanmiu/docx.svg?branch=master
|
||||||
[travis-url]: https://travis-ci.org/dolanmiu/docx
|
[travis-url]: https://travis-ci.org/dolanmiu/docx
|
||||||
|
[github-actions-workflow-image]: https://github.com/dolanmiu/docx/workflows/Default/badge.svg
|
||||||
|
[github-actions-workflow-url]: https://github.com/dolanmiu/docx/actions
|
||||||
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
[daviddm-image]: https://david-dm.org/dolanmiu/docx.svg?theme=shields.io
|
||||||
[daviddm-url]: https://david-dm.org/dolanmiu/docx
|
[daviddm-url]: https://david-dm.org/dolanmiu/docx
|
||||||
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
[snky-image]: https://snyk.io/test/github/dolanmiu/docx/badge.svg
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
properties: {},
|
properties: {},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -22,6 +22,8 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -129,9 +129,9 @@ const achievements = [
|
|||||||
class DocumentCreator {
|
class DocumentCreator {
|
||||||
// tslint:disable-next-line: typedef
|
// tslint:disable-next-line: typedef
|
||||||
public create([experiences, educations, skills, achivements]): Document {
|
public create([experiences, educations, skills, achivements]): Document {
|
||||||
const document = new Document();
|
const document = new Document({
|
||||||
|
sections: [
|
||||||
document.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Dolan Miu",
|
text: "Dolan Miu",
|
||||||
@ -143,7 +143,10 @@ class DocumentCreator {
|
|||||||
.map((education) => {
|
.map((education) => {
|
||||||
const arr: Paragraph[] = [];
|
const arr: Paragraph[] = [];
|
||||||
arr.push(
|
arr.push(
|
||||||
this.createInstitutionHeader(education.schoolName, `${education.startDate.year} - ${education.endDate.year}`),
|
this.createInstitutionHeader(
|
||||||
|
education.schoolName,
|
||||||
|
`${education.startDate.year} - ${education.endDate.year}`,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
arr.push(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`));
|
arr.push(this.createRoleText(`${education.fieldOfStudy} - ${education.degree}`));
|
||||||
|
|
||||||
@ -190,10 +193,13 @@ class DocumentCreator {
|
|||||||
),
|
),
|
||||||
new Paragraph("More references upon request"),
|
new Paragraph("More references upon request"),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
|
text:
|
||||||
|
"This CV was generated in real-time based on my Linked-In profile from my personal website www.dolan.bio.",
|
||||||
alignment: AlignmentType.CENTER,
|
alignment: AlignmentType.CENTER,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
return document;
|
return document;
|
||||||
@ -204,7 +210,10 @@ class DocumentCreator {
|
|||||||
alignment: AlignmentType.CENTER,
|
alignment: AlignmentType.CENTER,
|
||||||
children: [
|
children: [
|
||||||
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
|
new TextRun(`Mobile: ${phoneNumber} | LinkedIn: ${profileUrl} | Email: ${email}`),
|
||||||
new TextRun("Address: 58 Elm Avenue, Kent ME4 6ER, UK").break(),
|
new TextRun({
|
||||||
|
text: "Address: 58 Elm Avenue, Kent ME4 6ER, UK",
|
||||||
|
break: 1,
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import {
|
import {
|
||||||
AlignmentType,
|
AlignmentType,
|
||||||
|
convertInchesToTwip,
|
||||||
Document,
|
Document,
|
||||||
Footer,
|
Footer,
|
||||||
HeadingLevel,
|
HeadingLevel,
|
||||||
Media,
|
ImageRun,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
Table,
|
Table,
|
||||||
@ -16,15 +17,43 @@ import {
|
|||||||
UnderlineType,
|
UnderlineType,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
|
|
||||||
|
const table = new Table({
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 1.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 2.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 3.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Test cell 4.")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
styles: {
|
styles: {
|
||||||
paragraphStyles: [
|
default: {
|
||||||
{
|
heading1: {
|
||||||
id: "Heading1",
|
|
||||||
name: "Heading 1",
|
|
||||||
basedOn: "Normal",
|
|
||||||
next: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
run: {
|
run: {
|
||||||
font: "Calibri",
|
font: "Calibri",
|
||||||
size: 52,
|
size: 52,
|
||||||
@ -40,12 +69,7 @@ const doc = new Document({
|
|||||||
spacing: { line: 340 },
|
spacing: { line: 340 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
heading2: {
|
||||||
id: "Heading2",
|
|
||||||
name: "Heading 2",
|
|
||||||
basedOn: "Normal",
|
|
||||||
next: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
run: {
|
run: {
|
||||||
font: "Calibri",
|
font: "Calibri",
|
||||||
size: 26,
|
size: 26,
|
||||||
@ -55,12 +79,7 @@ const doc = new Document({
|
|||||||
spacing: { line: 340 },
|
spacing: { line: 340 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
heading3: {
|
||||||
id: "Heading3",
|
|
||||||
name: "Heading 3",
|
|
||||||
basedOn: "Normal",
|
|
||||||
next: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
run: {
|
run: {
|
||||||
font: "Calibri",
|
font: "Calibri",
|
||||||
size: 26,
|
size: 26,
|
||||||
@ -70,12 +89,7 @@ const doc = new Document({
|
|||||||
spacing: { line: 276 },
|
spacing: { line: 276 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
heading4: {
|
||||||
id: "Heading4",
|
|
||||||
name: "Heading 4",
|
|
||||||
basedOn: "Normal",
|
|
||||||
next: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
run: {
|
run: {
|
||||||
font: "Calibri",
|
font: "Calibri",
|
||||||
size: 26,
|
size: 26,
|
||||||
@ -85,6 +99,8 @@ const doc = new Document({
|
|||||||
alignment: AlignmentType.JUSTIFIED,
|
alignment: AlignmentType.JUSTIFIED,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
paragraphStyles: [
|
||||||
{
|
{
|
||||||
id: "normalPara",
|
id: "normalPara",
|
||||||
name: "Normal Para",
|
name: "Normal Para",
|
||||||
@ -128,7 +144,7 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
paragraph: {
|
paragraph: {
|
||||||
spacing: { line: 276 },
|
spacing: { line: 276 },
|
||||||
indent: { left: 720 },
|
indent: { left: convertInchesToTwip(0.5) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -139,61 +155,20 @@ const doc = new Document({
|
|||||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
{
|
{
|
||||||
id: "ListParagraph",
|
|
||||||
name: "List Paragraph",
|
|
||||||
basedOn: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
const table = new Table({
|
|
||||||
rows: [
|
|
||||||
new TableRow({
|
|
||||||
children: [
|
|
||||||
new TableCell({
|
|
||||||
children: [new Paragraph("Test cell 1.")],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
new TableRow({
|
|
||||||
children: [
|
|
||||||
new TableCell({
|
|
||||||
children: [new Paragraph("Test cell 2.")],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
new TableRow({
|
|
||||||
children: [
|
|
||||||
new TableCell({
|
|
||||||
children: [new Paragraph("Test cell 3.")],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
new TableRow({
|
|
||||||
children: [
|
|
||||||
new TableCell({
|
|
||||||
children: [new Paragraph("Test cell 4.")],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
});
|
|
||||||
|
|
||||||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
properties: {
|
properties: {
|
||||||
|
page: {
|
||||||
|
margin: {
|
||||||
top: 700,
|
top: 700,
|
||||||
right: 700,
|
right: 700,
|
||||||
bottom: 700,
|
bottom: 700,
|
||||||
left: 700,
|
left: 700,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: new Footer({
|
default: new Footer({
|
||||||
children: [
|
children: [
|
||||||
@ -206,7 +181,17 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph(image),
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "HEADING",
|
text: "HEADING",
|
||||||
heading: HeadingLevel.HEADING_1,
|
heading: HeadingLevel.HEADING_1,
|
||||||
@ -245,17 +230,39 @@ doc.addSection({
|
|||||||
style: "normalPara",
|
style: "normalPara",
|
||||||
}),
|
}),
|
||||||
table,
|
table,
|
||||||
new Paragraph(image1),
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Test",
|
text: "Test",
|
||||||
style: "normalPara2",
|
style: "normalPara2",
|
||||||
}),
|
}),
|
||||||
new Paragraph(image2),
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Test 2",
|
text: "Test 2",
|
||||||
style: "normalPara2",
|
style: "normalPara2",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,17 +1,60 @@
|
|||||||
// Scaling images
|
// Scaling images
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Media, Packer, Paragraph } from "../build";
|
import { Document, ImageRun, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 50, 50);
|
{
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 100, 100);
|
children: [
|
||||||
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 250, 250);
|
new Paragraph("Hello World"),
|
||||||
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 400, 400);
|
new Paragraph({
|
||||||
|
children: [
|
||||||
doc.addSection({
|
new ImageRun({
|
||||||
children: [new Paragraph("Hello World"), new Paragraph(image), new Paragraph(image2), new Paragraph(image3), new Paragraph(image4)],
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 50,
|
||||||
|
height: 50,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 250,
|
||||||
|
height: 250,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 400,
|
||||||
|
height: 400,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -7,9 +7,8 @@ const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
|
|||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
title: "Title",
|
title: "Title",
|
||||||
externalStyles: styles,
|
externalStyles: styles,
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Cool Heading Text",
|
text: "Cool Heading Text",
|
||||||
@ -25,6 +24,8 @@ doc.addSection({
|
|||||||
style: "MyFancyStyle",
|
style: "MyFancyStyle",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
// Page numbers
|
// Page numbers
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build";
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
|
properties: {
|
||||||
|
titlePage: true,
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
@ -34,12 +37,42 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("My Title "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Footer - Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
first: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("First Page Footer "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("First Page"), new PageBreak()],
|
children: [new TextRun("First Page"), new PageBreak()],
|
||||||
}),
|
}),
|
||||||
new Paragraph("Second Page"),
|
new Paragraph("Second Page"),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph } from "../build";
|
import { Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph("Hello World"),
|
new Paragraph("Hello World"),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -13,6 +13,8 @@ doc.addSection({
|
|||||||
pageBreakBefore: true,
|
pageBreakBefore: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,13 +3,20 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Footer, Header, Packer, PageNumber, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
|
import { Document, Footer, Header, Packer, PageNumber, PageNumberFormat, PageOrientation, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [new Paragraph("Hello World")],
|
children: [new Paragraph("Hello World")],
|
||||||
});
|
},
|
||||||
|
{
|
||||||
doc.addSection({
|
properties: {
|
||||||
|
page: {
|
||||||
|
pageNumbers: {
|
||||||
|
start: 1,
|
||||||
|
formatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [new Paragraph("First Default Header on another page")],
|
children: [new Paragraph("First Default Header on another page")],
|
||||||
@ -20,14 +27,21 @@ doc.addSection({
|
|||||||
children: [new Paragraph("Footer on another page")],
|
children: [new Paragraph("Footer on another page")],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
properties: {
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
},
|
|
||||||
children: [new Paragraph("hello")],
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.addSection({
|
children: [new Paragraph("hello")],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
size: {
|
||||||
|
orientation: PageOrientation.LANDSCAPE,
|
||||||
|
},
|
||||||
|
pageNumbers: {
|
||||||
|
start: 1,
|
||||||
|
formatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [new Paragraph("Second Default Header on another page")],
|
children: [new Paragraph("Second Default Header on another page")],
|
||||||
@ -38,37 +52,16 @@ doc.addSection({
|
|||||||
children: [new Paragraph("Footer on another page")],
|
children: [new Paragraph("Footer on another page")],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
size: {
|
|
||||||
orientation: PageOrientation.LANDSCAPE,
|
|
||||||
},
|
|
||||||
properties: {
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
},
|
|
||||||
children: [new Paragraph("hello in landscape")],
|
children: [new Paragraph("hello in landscape")],
|
||||||
});
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
headers: {
|
|
||||||
default: new Header({
|
|
||||||
children: [
|
|
||||||
new Paragraph({
|
|
||||||
children: [
|
|
||||||
new TextRun({
|
|
||||||
children: ["Page number: ", PageNumber.CURRENT],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
size: {
|
size: {
|
||||||
orientation: PageOrientation.PORTRAIT,
|
orientation: PageOrientation.PORTRAIT,
|
||||||
},
|
},
|
||||||
children: [new Paragraph("Page number in the header must be 2, because it continues from the previous section.")],
|
},
|
||||||
});
|
},
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
@ -82,18 +75,51 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
children: [new Paragraph("Page number in the header must be 2, because it continues from the previous section.")],
|
||||||
|
},
|
||||||
|
{
|
||||||
properties: {
|
properties: {
|
||||||
pageNumberFormatType: PageNumberFormat.UPPER_ROMAN,
|
page: {
|
||||||
|
size: {
|
||||||
orientation: PageOrientation.PORTRAIT,
|
orientation: PageOrientation.PORTRAIT,
|
||||||
},
|
},
|
||||||
|
pageNumbers: {
|
||||||
|
formatType: PageNumberFormat.UPPER_ROMAN,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph(
|
new Paragraph(
|
||||||
"Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.",
|
"Page number in the header must be III, because it continues from the previous section, but is defined as upper roman.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
},
|
||||||
|
{
|
||||||
doc.addSection({
|
properties: {
|
||||||
|
page: {
|
||||||
|
size: {
|
||||||
|
orientation: PageOrientation.PORTRAIT,
|
||||||
|
},
|
||||||
|
pageNumbers: {
|
||||||
|
start: 25,
|
||||||
|
formatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
@ -107,15 +133,12 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
size: {
|
|
||||||
orientation: PageOrientation.PORTRAIT,
|
|
||||||
},
|
|
||||||
properties: {
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
pageNumberStart: 25,
|
|
||||||
},
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph("Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section."),
|
new Paragraph(
|
||||||
|
"Page number in the header must be 25, because it is defined to start at 25 and to be decimal in this section.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -4,17 +4,16 @@ import * as fs from "fs";
|
|||||||
import { Document, FootnoteReferenceRun, Packer, Paragraph, TextRun } from "../build";
|
import { Document, FootnoteReferenceRun, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
footnotes: [
|
footnotes: {
|
||||||
new Paragraph("Foo"),
|
1: { children: [new Paragraph("Foo"), new Paragraph("Bar")] },
|
||||||
new Paragraph("Test"),
|
2: { children: [new Paragraph("Test")] },
|
||||||
new Paragraph("My amazing reference"),
|
3: { children: [new Paragraph("My amazing reference")] },
|
||||||
new Paragraph("Foo1"),
|
4: { children: [new Paragraph("Foo1")] },
|
||||||
new Paragraph("Test1"),
|
5: { children: [new Paragraph("Test1")] },
|
||||||
new Paragraph("My amazing reference1"),
|
6: { children: [new Paragraph("My amazing reference1")] },
|
||||||
],
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -30,9 +29,8 @@ doc.addSection({
|
|||||||
children: [new TextRun("Hello World"), new FootnoteReferenceRun(3)],
|
children: [new TextRun("Hello World"), new FootnoteReferenceRun(3)],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
},
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -48,6 +46,8 @@ doc.addSection({
|
|||||||
children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)],
|
children: [new TextRun("Hello World"), new FootnoteReferenceRun(6)],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,20 +1,28 @@
|
|||||||
// Insert image from a buffer
|
// Insert image from a buffer
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Media, Packer, Paragraph } from "../build";
|
import { Document, ImageRun, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const imageBase64Data = `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`;
|
const imageBase64Data = `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`;
|
||||||
|
|
||||||
const image = Media.addImage(doc, Buffer.from(imageBase64Data, "base64"), 100, 100);
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [image],
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: Buffer.from(imageBase64Data, "base64"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -21,6 +21,8 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBase64String(doc).then((str) => {
|
Packer.toBase64String(doc).then((str) => {
|
||||||
|
@ -1,20 +1,25 @@
|
|||||||
// Example on how to customise the look at feel using Styles
|
// Example on how to customise the look at feel using Styles
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, HeadingLevel, Packer, Paragraph, TextRun, UnderlineType } from "../build";
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
convertInchesToTwip,
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
LevelFormat,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
TextRun,
|
||||||
|
UnderlineType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
creator: "Clippy",
|
creator: "Clippy",
|
||||||
title: "Sample Document",
|
title: "Sample Document",
|
||||||
description: "A brief example of using docx",
|
description: "A brief example of using docx",
|
||||||
styles: {
|
styles: {
|
||||||
paragraphStyles: [
|
default: {
|
||||||
{
|
heading1: {
|
||||||
id: "Heading1",
|
|
||||||
name: "Heading 1",
|
|
||||||
basedOn: "Normal",
|
|
||||||
next: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
run: {
|
run: {
|
||||||
size: 28,
|
size: 28,
|
||||||
bold: true,
|
bold: true,
|
||||||
@ -27,12 +32,7 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
heading2: {
|
||||||
id: "Heading2",
|
|
||||||
name: "Heading 2",
|
|
||||||
basedOn: "Normal",
|
|
||||||
next: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
run: {
|
run: {
|
||||||
size: 26,
|
size: 26,
|
||||||
bold: true,
|
bold: true,
|
||||||
@ -48,6 +48,13 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
listParagraph: {
|
||||||
|
run: {
|
||||||
|
color: "#FF0000",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
paragraphStyles: [
|
||||||
{
|
{
|
||||||
id: "aside",
|
id: "aside",
|
||||||
name: "Aside",
|
name: "Aside",
|
||||||
@ -59,7 +66,7 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: {
|
indent: {
|
||||||
left: 720,
|
left: convertInchesToTwip(0.5),
|
||||||
},
|
},
|
||||||
spacing: {
|
spacing: {
|
||||||
line: 276,
|
line: 276,
|
||||||
@ -75,12 +82,6 @@ const doc = new Document({
|
|||||||
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
id: "ListParagraph",
|
|
||||||
name: "List Paragraph",
|
|
||||||
basedOn: "Normal",
|
|
||||||
quickFormat: true,
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
numbering: {
|
numbering: {
|
||||||
@ -90,7 +91,7 @@ const doc = new Document({
|
|||||||
levels: [
|
levels: [
|
||||||
{
|
{
|
||||||
level: 0,
|
level: 0,
|
||||||
format: "lowerLetter",
|
format: LevelFormat.LOWER_LETTER,
|
||||||
text: "%1)",
|
text: "%1)",
|
||||||
alignment: AlignmentType.LEFT,
|
alignment: AlignmentType.LEFT,
|
||||||
},
|
},
|
||||||
@ -98,9 +99,8 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Test heading1, bold and italicized",
|
text: "Test heading1, bold and italicized",
|
||||||
@ -117,6 +117,7 @@ doc.addSection({
|
|||||||
reference: "my-crazy-numbering",
|
reference: "my-crazy-numbering",
|
||||||
level: 0,
|
level: 0,
|
||||||
},
|
},
|
||||||
|
style: "aside",
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Option5 -- override 2 to 5",
|
text: "Option5 -- override 2 to 5",
|
||||||
@ -170,6 +171,19 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
style: "Strong",
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Strong Style",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: " - Very strong.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const table = new Table({
|
{
|
||||||
|
children: [
|
||||||
|
new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
@ -94,10 +96,12 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({ children: [table] });
|
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
// This demo shows how to create bookmarks then link to them with internal hyperlinks
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Bookmark, Document, HeadingLevel, HyperlinkRef, HyperlinkType, Packer, PageBreak, Paragraph } from "../build";
|
import { Bookmark, Document, Footer, HeadingLevel, InternalHyperlink, Packer, PageBreak, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const LOREM_IPSUM =
|
const LOREM_IPSUM =
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam mi velit, convallis convallis scelerisque nec, faucibus nec leo. Phasellus at posuere mauris, tempus dignissim velit. Integer et tortor dolor. Duis auctor efficitur mattis. Vivamus ut metus accumsan tellus auctor sollicitudin venenatis et nibh. Cras quis massa ac metus fringilla venenatis. Proin rutrum mauris purus, ut suscipit magna consectetur id. Integer consectetur sollicitudin ante, vitae faucibus neque efficitur in. Praesent ultricies nibh lectus. Mauris pharetra id odio eget iaculis. Duis dictum, risus id pellentesque rutrum, lorem quam malesuada massa, quis ullamcorper turpis urna a diam. Cras vulputate metus vel massa porta ullamcorper. Etiam porta condimentum nulla nec tristique. Sed nulla urna, pharetra non tortor sed, sollicitudin molestie diam. Maecenas enim leo, feugiat eget vehicula id, sollicitudin vitae ante.";
|
||||||
@ -10,19 +10,34 @@ const doc = new Document({
|
|||||||
creator: "Clippy",
|
creator: "Clippy",
|
||||||
title: "Sample Document",
|
title: "Sample Document",
|
||||||
description: "A brief example of using docx with bookmarks and internal hyperlinks",
|
description: "A brief example of using docx with bookmarks and internal hyperlinks",
|
||||||
hyperlinks: {
|
sections: [
|
||||||
myAnchorId: {
|
{
|
||||||
text: "Hyperlink",
|
footers: {
|
||||||
type: HyperlinkType.INTERNAL,
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new InternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "Click here!",
|
||||||
|
style: "Hyperlink",
|
||||||
|
}),
|
||||||
|
anchor: "myAnchorId",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
heading: HeadingLevel.HEADING_1,
|
heading: HeadingLevel.HEADING_1,
|
||||||
children: [new Bookmark("myAnchorId", "Lorem Ipsum")],
|
children: [
|
||||||
|
new Bookmark({
|
||||||
|
id: "myAnchorId",
|
||||||
|
children: [new TextRun("Lorem Ipsum")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
new Paragraph("\n"),
|
new Paragraph("\n"),
|
||||||
new Paragraph(LOREM_IPSUM),
|
new Paragraph(LOREM_IPSUM),
|
||||||
@ -30,8 +45,18 @@ doc.addSection({
|
|||||||
children: [new PageBreak()],
|
children: [new PageBreak()],
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new HyperlinkRef("myAnchorId")],
|
children: [
|
||||||
|
new InternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "Anchor Text",
|
||||||
|
style: "Hyperlink",
|
||||||
}),
|
}),
|
||||||
|
anchor: "myAnchorId",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
// This demo shows right to left for special languages
|
// This demo shows right to left for special languages
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "../build";
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
bidirectional: true,
|
bidirectional: true,
|
||||||
@ -36,6 +36,33 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Table({
|
||||||
|
visuallyRightToLeft: true,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("שלום עולם")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("שלום עולם")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,29 +1,83 @@
|
|||||||
// This demo adds an image to the Media cache, and then insert to the document afterwards
|
// This demo adds an image to the Media cache, and then insert to the document afterwards
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Media, Packer, Paragraph, TextRun } from "../build";
|
import { Document, ImageRun, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/dog.png"));
|
|
||||||
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"));
|
|
||||||
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"));
|
|
||||||
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
const imageBase64Data = `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`;
|
const imageBase64Data = `iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAACzVBMVEUAAAAAAAAAAAAAAAA/AD8zMzMqKiokJCQfHx8cHBwZGRkuFxcqFSonJyckJCQiIiIfHx8eHh4cHBwoGhomGSYkJCQhISEfHx8eHh4nHR0lHBwkGyQjIyMiIiIgICAfHx8mHh4lHh4kHR0jHCMiGyIhISEgICAfHx8lHx8kHh4jHR0hHCEhISEgICAlHx8kHx8jHh4jHh4iHSIhHCEhISElICAkHx8jHx8jHh4iHh4iHSIhHSElICAkICAjHx8jHx8iHh4iHh4hHiEhHSEkICAjHx8iHx8iHx8hHh4hHiEkHSEjHSAjHx8iHx8iHx8hHh4kHiEkHiEjHSAiHx8hHx8hHh4kHiEjHiAjHSAiHx8iHx8hHx8kHh4jHiEjHiAjHiAiICAiHx8kHx8jHh4jHiEjHiAiHiAiHSAiHx8jHx8jHx8jHiAiHiAiHiAiHSAiHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8jHx8iHiAiHiAiHiAjHx8jHx8jHx8iHx8iHSAiHiAjHiAjHx8jHx8hHx8iHx8iHyAiHiAjHiAjHiAjHh4hHx8iHx8iHx8iHyAjHSAjHiAjHiAjHh4hHx8iHx8iHx8jHyAjHiAhHh4iHx8iHx8jHyAjHSAjHSAhHiAhHh4iHx8iHx8jHx8jHyAjHSAjHSAiHh4iHh4jHx8jHx8jHyAjHyAhHSAhHSAiHh4iHh4jHx8jHx8jHyAhHyAhHSAiHSAiHh4jHh4jHx8jHx8jHyAhHyAhHSAiHSAjHR4jHh4jHx8jHx8hHyAhHyAiHSAjHSAjHR4jHh4jHx8hHx8hHyAhHyAiHyAjHSAjHR4jHR4hHh4hHx8hHyAiHyAjHyAjHSAjHR4jHR4hHh4hHx8hHyAjHyAjHyAjHSAjHR4hHR4hHR4hHx8iHyAjHyAjHyAjHSAhHR4hHR4hHR4hHx8jHyAjHyAjHyAjHyC9S2xeAAAA7nRSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFxgZGhscHR4fICEiIyQlJicoKSorLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZISUpLTE1OUFFSU1RVVllaW1xdXmBhYmNkZWZnaGprbG1ub3Byc3R1dnd4eXp8fn+AgYKDhIWGiImKi4yNj5CRkpOUlZaXmJmam5ydnp+goaKjpKaoqqusra6vsLGys7S1tri5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+fkZpVQAABcBJREFUGBntwftjlQMcBvDnnLNL22qzJjWlKLHFVogyty3SiFq6EZliqZGyhnSxsLlMRahYoZKRFcul5dKFCatYqWZaNKvWtrPz/A2+7/b27qRzec/lPfvl/XxgMplMJpPJZDKZAtA9HJ3ppnIez0KnSdtC0RCNznHdJrbrh85wdSlVVRaEXuoGamYi5K5430HNiTiEWHKJg05eRWgNfKeV7RxbqUhGKPV/207VupQ8is0IoX5vtFC18SqEHaK4GyHTZ2kzVR8PBTCO4oANIZL4ShNVZcOhKKeYg9DoWdhI1ec3os2VFI0JCIUez5+i6st0qJZRrEAIJCw+QdW223BG/EmKwTBc/IJ/qfp2FDrkUnwFo8U9dZyqnaPhxLqfYjyM1S3vb6p+GGOBszsojoTDSDFz6qj66R4LzvYJxVMwUNRjf1H1ywQr/megg2RzLximy8waqvbda8M5iijegVEiHjlM1W/3h+FcXesphsMY4dMOUnUgOxyuPEzxPQwRNvV3qg5Nj4BreyimwADWe/dRVTMjEm6MoGLzGwtystL6RyOY3qSqdlYU3FpLZw1VW0sK5943MvUCKwJ1noNtjs6Ohge76Zq9ZkfpigU5WWkDYuCfbs1U5HWFR8/Qq4a9W0uK5k4ZmdrTCl8spGIePLPlbqqsc1Afe83O0hULc8alDYiBd7ZyitYMeBfR55rR2fOKP6ioPk2dGvZ+UVI0d8rtqT2tcCexlqK2F3wRn5Q+YVbBqrLKOupkr9lZujAOrmS0UpTb4JeIPkNHZ+cXr6uoPk2vyuBSPhWLEKj45PQJuQWryyqP0Z14uGLdROHIRNBEXDR09EP5r62rOHCazhrD4VKPwxTH+sIA3ZPTJ+YuWV22n+IruHFDC8X2CBjnPoolcGc2FYUwzmsUWXDHsoGKLBhmN0VvuBVfTVE/AAbpaid5CB4MbaLY1QXGuIViLTyZQcVyGGMuxWPwaA0Vk2GI9RRp8Ci2iuLkIBjhT5LNUfAspZFiTwyC72KK7+DNg1SsRvCNp3gZXq2k4iEEXSHFJHgVXUlxejCCbTvFAHiXdIJiXxyCK7KJ5FHoMZGK9xBcwyg2QpdlVMxEUM2iyIMuXXZQNF+HswxMsSAAJRQjoE//eoqDCXBSTO6f1xd+O0iyNRY6jaWi1ALNYCocZROj4JdEikroVkjFk9DcStXxpdfCD2MoXodu4RUU9ptxxmXssOfxnvDVcxRTod9FxyhqLoAqis5aPhwTDp9spRgEH2Q6KLbYoKqlaKTm6Isp0C/sJMnjFvhiERXPQvUNRe9p29lhR04CdBpC8Sl8YiuncIxEuzUUg4Dkgj+paVozygY9plPMh28SaymO9kabAopREGF3vt9MzeFFl8G7lRSZ8FFGK8XX4VA8QjEd7XrM3M0OXz8YCy+qKBLgq3wqnofiTorF0Ax56Rg1J1elW+BBAsVe+My6iYq7IK6keBdOIseV2qn5Pb8f3MqkWAXf9ThM8c8lAOIotuFsF875lRrH5klRcG0+xcPwQ1oLxfeRAP4heQTnGL78X2rqlw2DK59SXAV/zKaiGMAuko5InCt68mcOan5+ohf+z1pP8lQY/GHZQMV4YD3FpXDp4qerqbF/lBWBswyi+AL+ia+maLgcRRQj4IYlY/UpauqKBsPJAxQF8NM1TRQ/RudSPAD34rK3scOuR8/HGcspxsJfOVS8NZbiGXiUtPgINU3v3WFDmx8pEuG3EiqKKVbCC1vm2iZqap5LAtCtleQf8F9sFYWDohzeJczYyQ4V2bEZFGsQgJRGqqqhS2phHTWn9lDkIhBTqWqxQZ+IsRvtdHY9AvI2VX2hW68nfqGmuQsCEl3JdjfCF8OW1bPdtwhQ0gm2mQzfRE3a7KCYj0BNZJs8+Kxf/r6WtTEI2FIqlsMfFgRB5A6KUnSe/vUkX0AnuvUIt8SjM1m6wWQymUwmk8lkMgXRf5vi8rLQxtUhAAAAAElFTkSuQmCC`;
|
||||||
const image6 = Media.addImage(doc, Buffer.from(imageBase64Data, "base64"), 100, 100);
|
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Hello World"), image5],
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/parrots.bmp"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
new Paragraph(image),
|
],
|
||||||
new Paragraph(image2),
|
}),
|
||||||
new Paragraph(image3),
|
new Paragraph({
|
||||||
new Paragraph(image4),
|
children: [
|
||||||
new Paragraph(image6),
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/dog.png"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/cat.jpg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/parrots.bmp"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: Buffer.from(imageBase64Data, "base64"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// Add image to table cell
|
// Add image to table cell
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Media, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { Document, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
{
|
||||||
|
children: [
|
||||||
const table = new Table({
|
new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
@ -31,7 +31,19 @@ const table = new Table({
|
|||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [new Paragraph(image)],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [],
|
children: [],
|
||||||
@ -74,10 +86,10 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
}),
|
||||||
|
],
|
||||||
doc.addSection({
|
},
|
||||||
children: [table],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
51
demo/25-table-xml-styles.ts
Normal file
51
demo/25-table-xml-styles.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
// Example of how you would create a table and add data to it
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||||
|
|
||||||
|
const styles = fs.readFileSync("./demo/assets/custom-styles.xml", "utf-8");
|
||||||
|
|
||||||
|
// Create a table and pass the XML Style
|
||||||
|
const table = new Table({
|
||||||
|
style: "MyCustomTableStyle",
|
||||||
|
width: {
|
||||||
|
size: 9070,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Header Colum 1")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Header Colum 2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Column Content 3")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph("Column Content 2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
title: "Title",
|
||||||
|
externalStyles: styles,
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [table],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph } from "../build";
|
import { Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph("No border!"),
|
new Paragraph("No border!"),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -26,6 +26,8 @@ doc.addSection({
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Custom styles using JavaScript configuration
|
// Custom styles using JavaScript configuration
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
|
import { Document, convertInchesToTwip, HeadingLevel, Packer, Paragraph, UnderlineType } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
styles: {
|
styles: {
|
||||||
@ -17,7 +17,7 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: {
|
indent: {
|
||||||
left: 720,
|
left: convertInchesToTwip(0.5),
|
||||||
},
|
},
|
||||||
spacing: {
|
spacing: {
|
||||||
line: 276,
|
line: 276,
|
||||||
@ -47,9 +47,8 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Hello",
|
text: "Hello",
|
||||||
@ -60,6 +59,8 @@ doc.addSection({
|
|||||||
heading: HeadingLevel.HEADING_2,
|
heading: HeadingLevel.HEADING_2,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,6 +3,11 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "../build";
|
import { File, HeadingLevel, Packer, Paragraph, StyleLevel, TableOfContents } from "../build";
|
||||||
|
|
||||||
|
// WordprocessingML docs for TableOfContents can be found here:
|
||||||
|
// http://officeopenxml.com/WPtableOfContents.php
|
||||||
|
|
||||||
|
// Let's define the properties for generate a TOC for heading 1-5 and MySpectacularStyle,
|
||||||
|
// making the entries be hyperlinks for the paragraph
|
||||||
const doc = new File({
|
const doc = new File({
|
||||||
styles: {
|
styles: {
|
||||||
paragraphStyles: [
|
paragraphStyles: [
|
||||||
@ -19,15 +24,8 @@ const doc = new File({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
// WordprocessingML docs for TableOfContents can be found here:
|
|
||||||
// http://officeopenxml.com/WPtableOfContents.php
|
|
||||||
|
|
||||||
// Let's define the properties for generate a TOC for heading 1-5 and MySpectacularStyle,
|
|
||||||
// making the entries be hyperlinks for the paragraph
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new TableOfContents("Summary", {
|
new TableOfContents("Summary", {
|
||||||
hyperlink: true,
|
hyperlink: true,
|
||||||
@ -57,6 +55,8 @@ doc.addSection({
|
|||||||
pageBreakBefore: true,
|
pageBreakBefore: true,
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
// Numbered lists
|
// Numbered lists
|
||||||
|
// The lists can also be restarted by specifying the instance number
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Packer, Paragraph } from "../build";
|
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
numbering: {
|
numbering: {
|
||||||
@ -10,12 +11,12 @@ const doc = new Document({
|
|||||||
levels: [
|
levels: [
|
||||||
{
|
{
|
||||||
level: 0,
|
level: 0,
|
||||||
format: "upperRoman",
|
format: LevelFormat.UPPER_ROMAN,
|
||||||
text: "%1",
|
text: "%1",
|
||||||
alignment: AlignmentType.START,
|
alignment: AlignmentType.START,
|
||||||
style: {
|
style: {
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: { left: 720, hanging: 260 },
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -26,23 +27,38 @@ const doc = new Document({
|
|||||||
levels: [
|
levels: [
|
||||||
{
|
{
|
||||||
level: 0,
|
level: 0,
|
||||||
format: "decimal",
|
format: LevelFormat.DECIMAL,
|
||||||
text: "%1",
|
text: "%1",
|
||||||
alignment: AlignmentType.START,
|
alignment: AlignmentType.START,
|
||||||
style: {
|
style: {
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: { left: 720, hanging: 260 },
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
reference: "my-number-numbering-reference",
|
reference: "my-number-numbering-reference",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.DECIMAL_ZERO,
|
||||||
|
text: "[%1]",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "line with contextual spacing",
|
text: "line with contextual spacing",
|
||||||
@ -109,6 +125,158 @@ doc.addSection({
|
|||||||
level: 0,
|
level: 0,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Next",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
instance: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
instance: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Next",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
instance: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
instance: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
instance: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Next",
|
||||||
|
heading: HeadingLevel.HEADING_2,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "test",
|
||||||
|
numbering: {
|
||||||
|
reference: "padded-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Numbering and bullet points example
|
// Numbering and bullet points example
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Packer, Paragraph } from "../build";
|
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
numbering: {
|
numbering: {
|
||||||
@ -11,40 +11,40 @@ const doc = new Document({
|
|||||||
levels: [
|
levels: [
|
||||||
{
|
{
|
||||||
level: 0,
|
level: 0,
|
||||||
format: "upperRoman",
|
format: LevelFormat.UPPER_ROMAN,
|
||||||
text: "%1",
|
text: "%1",
|
||||||
alignment: AlignmentType.START,
|
alignment: AlignmentType.START,
|
||||||
style: {
|
style: {
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: { left: 720, hanging: 260 },
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.18) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
level: 1,
|
level: 1,
|
||||||
format: "decimal",
|
format: LevelFormat.DECIMAL,
|
||||||
text: "%2.",
|
text: "%2.",
|
||||||
alignment: AlignmentType.START,
|
alignment: AlignmentType.START,
|
||||||
style: {
|
style: {
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: { left: 1440, hanging: 980 },
|
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.68) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
level: 2,
|
level: 2,
|
||||||
format: "lowerLetter",
|
format: LevelFormat.LOWER_LETTER,
|
||||||
text: "%3)",
|
text: "%3)",
|
||||||
alignment: AlignmentType.START,
|
alignment: AlignmentType.START,
|
||||||
style: {
|
style: {
|
||||||
paragraph: {
|
paragraph: {
|
||||||
indent: { left: 2160, hanging: 1700 },
|
indent: { left: convertInchesToTwip(1.5), hanging: convertInchesToTwip(1.18) },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
level: 3,
|
level: 3,
|
||||||
format: "upperLetter",
|
format: LevelFormat.UPPER_LETTER,
|
||||||
text: "%4)",
|
text: "%4)",
|
||||||
alignment: AlignmentType.START,
|
alignment: AlignmentType.START,
|
||||||
style: {
|
style: {
|
||||||
@ -55,11 +55,70 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.BULLET,
|
||||||
|
text: "\u1F60",
|
||||||
|
alignment: AlignmentType.LEFT,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
format: LevelFormat.BULLET,
|
||||||
|
text: "\u00A5",
|
||||||
|
alignment: AlignmentType.LEFT,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(1), hanging: convertInchesToTwip(0.25) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 2,
|
||||||
|
format: LevelFormat.BULLET,
|
||||||
|
text: "\u273F",
|
||||||
|
alignment: AlignmentType.LEFT,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 2160, hanging: convertInchesToTwip(0.25) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 3,
|
||||||
|
format: LevelFormat.BULLET,
|
||||||
|
text: "\u267A",
|
||||||
|
alignment: AlignmentType.LEFT,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 2880, hanging: convertInchesToTwip(0.25) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 4,
|
||||||
|
format: LevelFormat.BULLET,
|
||||||
|
text: "\u2603",
|
||||||
|
alignment: AlignmentType.LEFT,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 3600, hanging: convertInchesToTwip(0.25) },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
],
|
||||||
|
},
|
||||||
doc.addSection({
|
sections: [
|
||||||
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Hey you",
|
text: "Hey you",
|
||||||
@ -134,6 +193,61 @@ doc.addSection({
|
|||||||
level: 0,
|
level: 0,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Custom Bullet points",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "What's up fam",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hey you",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "What's up fam",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Hello World 2",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 2,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Yeah boi",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 3,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "my Awesome numbering",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 4,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Back to level 1",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-unique-bullet-points",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -12,16 +12,21 @@ fs.readFile(filePath, (err, data) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
importDotx.extract(data).then((templateDocument) => {
|
importDotx.extract(data).then((templateDocument) => {
|
||||||
const doc = new Document(undefined, {
|
const doc = new Document(
|
||||||
template: templateDocument,
|
{
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
properties: {
|
properties: {
|
||||||
titlePage: templateDocument.titlePageIsDefined,
|
titlePage: templateDocument.titlePageIsDefined,
|
||||||
},
|
},
|
||||||
children: [new Paragraph("Hello World")],
|
children: [new Paragraph("Hello World")],
|
||||||
});
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
template: templateDocument,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build";
|
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const table = new Table({
|
{
|
||||||
|
children: [
|
||||||
|
new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
@ -65,10 +67,10 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
}),
|
||||||
|
],
|
||||||
doc.addSection({
|
},
|
||||||
children: [table],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -2,9 +2,20 @@
|
|||||||
// Also includes an example on how to center tables
|
// Also includes an example on how to center tables
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, BorderStyle, Document, HeadingLevel, Packer, Paragraph, ShadingType, Table, TableCell, TableRow, WidthType } from "../build";
|
import {
|
||||||
|
AlignmentType,
|
||||||
const doc = new Document();
|
BorderStyle,
|
||||||
|
convertInchesToTwip,
|
||||||
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
ShadingType,
|
||||||
|
Table,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
WidthType,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
@ -37,10 +48,10 @@ const table2 = new Table({
|
|||||||
new TableCell({
|
new TableCell({
|
||||||
children: [new Paragraph("World")],
|
children: [new Paragraph("World")],
|
||||||
margins: {
|
margins: {
|
||||||
top: 1000,
|
top: convertInchesToTwip(0.69),
|
||||||
bottom: 1000,
|
bottom: convertInchesToTwip(0.69),
|
||||||
left: 1000,
|
left: convertInchesToTwip(0.69),
|
||||||
right: 1000,
|
right: convertInchesToTwip(0.69),
|
||||||
},
|
},
|
||||||
columnSpan: 3,
|
columnSpan: 3,
|
||||||
}),
|
}),
|
||||||
@ -64,7 +75,7 @@ const table2 = new Table({
|
|||||||
size: 100,
|
size: 100,
|
||||||
type: WidthType.AUTO,
|
type: WidthType.AUTO,
|
||||||
},
|
},
|
||||||
columnWidths: [1000, 1000, 1000],
|
columnWidths: [convertInchesToTwip(0.69), convertInchesToTwip(0.69), convertInchesToTwip(0.69)],
|
||||||
});
|
});
|
||||||
|
|
||||||
const table3 = new Table({
|
const table3 = new Table({
|
||||||
@ -119,14 +130,14 @@ const table3 = new Table({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
width: {
|
width: {
|
||||||
size: 7000,
|
size: convertInchesToTwip(4.86),
|
||||||
type: WidthType.DXA,
|
type: WidthType.DXA,
|
||||||
},
|
},
|
||||||
margins: {
|
margins: {
|
||||||
top: 400,
|
top: convertInchesToTwip(0.27),
|
||||||
bottom: 400,
|
bottom: convertInchesToTwip(0.27),
|
||||||
right: 400,
|
right: convertInchesToTwip(0.27),
|
||||||
left: 400,
|
left: convertInchesToTwip(0.27),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -355,9 +366,7 @@ const table8 = new Table({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [new TableCell({ children: [new Paragraph("4,1")] })],
|
||||||
new TableCell({ children: [new Paragraph("4,1")] }),
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
width: {
|
width: {
|
||||||
@ -365,8 +374,9 @@ const table8 = new Table({
|
|||||||
type: WidthType.PERCENTAGE,
|
type: WidthType.PERCENTAGE,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
const doc = new Document({
|
||||||
doc.addSection({
|
sections: [
|
||||||
|
{
|
||||||
children: [
|
children: [
|
||||||
table,
|
table,
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -390,6 +400,8 @@ doc.addSection({
|
|||||||
new Paragraph("Merging columns 5"),
|
new Paragraph("Merging columns 5"),
|
||||||
table8,
|
table8,
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "../build";
|
import { Document, Packer, Paragraph, SequentialIdentifier, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -40,6 +40,8 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -16,8 +16,6 @@ import {
|
|||||||
WidthType,
|
WidthType,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
@ -45,6 +43,10 @@ const table = new Table({
|
|||||||
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
|
relativeHorizontalPosition: RelativeHorizontalPosition.RIGHT,
|
||||||
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
|
relativeVerticalPosition: RelativeVerticalPosition.BOTTOM,
|
||||||
overlap: OverlapType.NEVER,
|
overlap: OverlapType.NEVER,
|
||||||
|
leftFromText: 1000,
|
||||||
|
rightFromText: 2000,
|
||||||
|
topFromText: 1500,
|
||||||
|
bottomFromText: 30,
|
||||||
},
|
},
|
||||||
width: {
|
width: {
|
||||||
size: 4535,
|
size: 4535,
|
||||||
@ -53,8 +55,12 @@ const table = new Table({
|
|||||||
layout: TableLayoutType.FIXED,
|
layout: TableLayoutType.FIXED,
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
children: [table],
|
children: [table],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,33 +1,101 @@
|
|||||||
// Example on how to add hyperlinks to websites
|
// Example on how to add hyperlinks to websites
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph, Media } from "../build";
|
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
hyperlinks: {
|
footnotes: {
|
||||||
myCoolLink: {
|
1: {
|
||||||
link: "http://www.example.com",
|
|
||||||
text: "Hyperlink",
|
|
||||||
type: HyperlinkType.EXTERNAL,
|
|
||||||
},
|
|
||||||
myOtherLink: {
|
|
||||||
link: "http://www.google.com",
|
|
||||||
text: "Google Link",
|
|
||||||
type: HyperlinkType.EXTERNAL,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new HyperlinkRef("myCoolLink")],
|
children: [
|
||||||
|
new TextRun("Click here for the "),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "Footnotes external hyperlink",
|
||||||
|
style: "Hyperlink",
|
||||||
|
}),
|
||||||
|
link: "http://www.example.com",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Click here for the "),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "Footer external hyperlink",
|
||||||
|
style: "Hyperlink",
|
||||||
|
}),
|
||||||
|
link: "http://www.example.com",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Click here for the "),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "Header external hyperlink",
|
||||||
|
style: "Hyperlink",
|
||||||
|
}),
|
||||||
|
link: "http://www.google.com",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ExternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "Anchor Text",
|
||||||
|
style: "Hyperlink",
|
||||||
|
}),
|
||||||
|
link: "http://www.example.com",
|
||||||
|
}),
|
||||||
|
new FootnoteReferenceRun(1),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [image1, new HyperlinkRef("myOtherLink")],
|
children: [
|
||||||
|
new ExternalHyperlink({
|
||||||
|
child: new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
}),
|
}),
|
||||||
|
link: "http://www.google.com",
|
||||||
|
}),
|
||||||
|
new ExternalHyperlink({
|
||||||
|
child: new TextRun({
|
||||||
|
text: "BBC News Link",
|
||||||
|
style: "Hyperlink",
|
||||||
|
}),
|
||||||
|
link: "https://www.bbc.co.uk/news",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,10 +1,7 @@
|
|||||||
// Add image to table cell in a header and body
|
// Add image to table cell in a header and body
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Header, Media, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { Document, Header, ImageRun, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
@ -30,7 +27,19 @@ const table = new Table({
|
|||||||
children: [],
|
children: [],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [new Paragraph(image)],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -58,13 +67,17 @@ const table = new Table({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Adding same table in the body and in the header
|
// Adding same table in the body and in the header
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [table],
|
children: [table],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [table],
|
children: [table],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,20 +1,53 @@
|
|||||||
// Add images to header and footer
|
// Add images to header and footer
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Header, Media, Packer, Paragraph } from "../build";
|
import { Document, Header, ImageRun, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
sections: [
|
||||||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
{
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [new Paragraph(image), new Paragraph(image1), new Paragraph(image2)],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [new Paragraph("Hello World")],
|
children: [new Paragraph("Hello World")],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -2,11 +2,29 @@
|
|||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
// import { Document, Packer, Paragraph } from "../build";
|
// import { Document, Packer, Paragraph } from "../build";
|
||||||
import { Document, Media, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build";
|
import { Document, ImageRun, Packer, Paragraph, TextWrappingSide, TextWrappingType } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula nec nulla vitae efficitur. Ut interdum mauris eu ipsum rhoncus, nec pharetra velit placerat. Sed vehicula libero ac urna molestie, id pharetra est pellentesque. Praesent iaculis vehicula fringilla. Duis pretium gravida orci eu vestibulum. Mauris tincidunt ipsum dolor, ut ornare dolor pellentesque id. Integer in nulla gravida, lacinia ante non, commodo ex. Vivamus vulputate nisl id lectus finibus vulputate. Ut et nisl mi. Cras fermentum augue arcu, ac accumsan elit euismod id. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed ac posuere nisi. Pellentesque tincidunt vehicula bibendum. Phasellus eleifend viverra nisl.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Proin ac purus faucibus, porttitor magna ut, cursus nisl. Vivamus ante purus, porta accumsan nibh eget, eleifend dignissim odio. Integer sed dictum est, aliquam lacinia justo. Donec ultrices auctor venenatis. Etiam interdum et elit nec elementum. Pellentesque nec viverra mauris. Etiam suscipit leo nec velit fringilla mattis. Pellentesque justo lacus, sodales eu condimentum in, dapibus finibus lacus. Morbi vitae nibh sit amet sem molestie feugiat. In non porttitor enim.",
|
||||||
|
),
|
||||||
|
new Paragraph(
|
||||||
|
"Ut eget diam cursus quam accumsan interdum at id ante. Ut mollis mollis arcu, eu scelerisque dui tempus in. Quisque aliquam, augue quis ornare aliquam, ex purus ultrices mauris, ut porta dolor dolor nec justo. Nunc a tempus odio, eu viverra arcu. Suspendisse vitae nibh nec mi pharetra tempus. Mauris ut ullamcorper sapien, et sagittis sapien. Vestibulum in urna metus. In scelerisque, massa id bibendum tempus, quam orci rutrum turpis, a feugiat nisi ligula id metus. Praesent id dictum purus. Proin interdum ipsum nulla.",
|
||||||
|
),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
offset: 2014400,
|
offset: 2014400,
|
||||||
@ -23,20 +41,11 @@ const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 20
|
|||||||
bottom: 201440,
|
bottom: 201440,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
],
|
||||||
doc.addSection({
|
}),
|
||||||
children: [
|
],
|
||||||
new Paragraph(
|
},
|
||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque vehicula nec nulla vitae efficitur. Ut interdum mauris eu ipsum rhoncus, nec pharetra velit placerat. Sed vehicula libero ac urna molestie, id pharetra est pellentesque. Praesent iaculis vehicula fringilla. Duis pretium gravida orci eu vestibulum. Mauris tincidunt ipsum dolor, ut ornare dolor pellentesque id. Integer in nulla gravida, lacinia ante non, commodo ex. Vivamus vulputate nisl id lectus finibus vulputate. Ut et nisl mi. Cras fermentum augue arcu, ac accumsan elit euismod id. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed ac posuere nisi. Pellentesque tincidunt vehicula bibendum. Phasellus eleifend viverra nisl.",
|
|
||||||
),
|
|
||||||
new Paragraph(
|
|
||||||
"Proin ac purus faucibus, porttitor magna ut, cursus nisl. Vivamus ante purus, porta accumsan nibh eget, eleifend dignissim odio. Integer sed dictum est, aliquam lacinia justo. Donec ultrices auctor venenatis. Etiam interdum et elit nec elementum. Pellentesque nec viverra mauris. Etiam suscipit leo nec velit fringilla mattis. Pellentesque justo lacus, sodales eu condimentum in, dapibus finibus lacus. Morbi vitae nibh sit amet sem molestie feugiat. In non porttitor enim.",
|
|
||||||
),
|
|
||||||
new Paragraph(
|
|
||||||
"Ut eget diam cursus quam accumsan interdum at id ante. Ut mollis mollis arcu, eu scelerisque dui tempus in. Quisque aliquam, augue quis ornare aliquam, ex purus ultrices mauris, ut porta dolor dolor nec justo. Nunc a tempus odio, eu viverra arcu. Suspendisse vitae nibh nec mi pharetra tempus. Mauris ut ullamcorper sapien, et sagittis sapien. Vestibulum in urna metus. In scelerisque, massa id bibendum tempus, quam orci rutrum turpis, a feugiat nisi ligula id metus. Praesent id dictum purus. Proin interdum ipsum nulla.",
|
|
||||||
),
|
|
||||||
new Paragraph(image),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -3,9 +3,17 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document({});
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
pageNumbers: {
|
||||||
|
start: 1,
|
||||||
|
formatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
@ -41,10 +49,6 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
properties: {
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
},
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Hello World 1"), new PageBreak()],
|
children: [new TextRun("Hello World 1"), new PageBreak()],
|
||||||
@ -62,6 +66,8 @@ doc.addSection({
|
|||||||
children: [new TextRun("Hello World 5"), new PageBreak()],
|
children: [new TextRun("Hello World 5"), new PageBreak()],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,11 +1,93 @@
|
|||||||
// Example of how you would create a table and add data to it
|
// Example of how you would create a table and add data to it
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow, WidthType } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
|
columnWidths: [3505, 5505],
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 3505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 5505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 3505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 5505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const table2 = new Table({
|
||||||
|
columnWidths: [4505, 4505],
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 4505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello")],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 4505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 4505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
width: {
|
||||||
|
size: 4505,
|
||||||
|
type: WidthType.DXA,
|
||||||
|
},
|
||||||
|
children: [new Paragraph("World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const table3 = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
@ -30,8 +112,19 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
children: [table],
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({ text: "Table with skewed widths" }),
|
||||||
|
table,
|
||||||
|
new Paragraph({ text: "Table with equal widths" }),
|
||||||
|
table2,
|
||||||
|
new Paragraph({ text: "Table without setting widths" }),
|
||||||
|
table3,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,12 +3,14 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build";
|
import { Document, HeadingLevel, LineNumberRestartFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
properties: {
|
properties: {
|
||||||
lineNumberCountBy: 1,
|
lineNumbers: {
|
||||||
lineNumberRestart: LineNumberRestartFormat.CONTINUOUS,
|
countBy: 1,
|
||||||
|
restart: LineNumberRestartFormat.CONTINUOUS,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -22,6 +24,8 @@ doc.addSection({
|
|||||||
"Sed laoreet id mattis egestas nam mollis elit lacinia convallis dui tincidunt ultricies habitant, pharetra per maximus interdum neque tempor risus efficitur morbi imperdiet senectus. Lectus laoreet senectus finibus inceptos donec potenti fermentum, ultrices eleifend odio suscipit magnis tellus maximus nibh, ac sit nullam eget felis himenaeos. Diam class sem magnis aenean commodo faucibus id proin mi, nullam sodales nec mus parturient ornare ad inceptos velit hendrerit, bibendum placerat eleifend integer facilisis urna dictumst suspendisse.",
|
"Sed laoreet id mattis egestas nam mollis elit lacinia convallis dui tincidunt ultricies habitant, pharetra per maximus interdum neque tempor risus efficitur morbi imperdiet senectus. Lectus laoreet senectus finibus inceptos donec potenti fermentum, ultrices eleifend odio suscipit magnis tellus maximus nibh, ac sit nullam eget felis himenaeos. Diam class sem magnis aenean commodo faucibus id proin mi, nullam sodales nec mus parturient ornare ad inceptos velit hendrerit, bibendum placerat eleifend integer facilisis urna dictumst suspendisse.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
@ -252,8 +250,12 @@ const table2 = new Table({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
children: [table, new Paragraph(""), table2],
|
children: [table, new Paragraph(""), table2],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
93
demo/42-restart-page-numbers.ts
Normal file
93
demo/42-restart-page-numbers.ts
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
// Page numbers - Start from 0 on a new section
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, Document, Header, Packer, PageBreak, PageNumber, PageNumberSeparator, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("My Title "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
first: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("First Page Header "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("First Page"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph("Second Page"),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
pageNumbers: {
|
||||||
|
start: 1,
|
||||||
|
separator: PageNumberSeparator.EM_DASH,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("My Title "),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
first: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.RIGHT,
|
||||||
|
children: [
|
||||||
|
new TextRun("First Page Header of Second section"),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Third Page"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph("Fourth Page"),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -3,8 +3,6 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import { Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
@ -75,8 +73,12 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
children: [table],
|
children: [table],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph } from "../build";
|
import { Document, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
properties: {
|
properties: {
|
||||||
column: {
|
column: {
|
||||||
space: 708,
|
space: 708,
|
||||||
@ -18,9 +18,8 @@ doc.addSection({
|
|||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
},
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
properties: {
|
properties: {
|
||||||
column: {
|
column: {
|
||||||
space: 708,
|
space: 708,
|
||||||
@ -33,6 +32,23 @@ doc.addSection({
|
|||||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
column: {
|
||||||
|
space: 708,
|
||||||
|
count: 2,
|
||||||
|
separate: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph("This text will be split into 2 columns on a page."),
|
||||||
|
new Paragraph(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build";
|
import { AlignmentType, Document, Header, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
@ -28,6 +28,8 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build";
|
import { AlignmentType, Document, Header, Packer, Paragraph, ShadingType, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
@ -28,10 +28,37 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.DIAGONAL_CROSS,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "Hello World for entire paragraph",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
emboss: true,
|
||||||
|
text: "Embossed text - hello world",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
imprint: true,
|
||||||
|
text: "Imprinted text - hello world",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
|
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, PageNumberFormat, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const header = new Header({
|
const header = new Header({
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -26,40 +24,51 @@ const footer = new Footer({
|
|||||||
children: [new Paragraph("Foo Bar corp. ")],
|
children: [new Paragraph("Foo Bar corp. ")],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
pageNumbers: {
|
||||||
|
start: 1,
|
||||||
|
formatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: header,
|
default: header,
|
||||||
},
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: footer,
|
default: footer,
|
||||||
},
|
},
|
||||||
properties: {
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
},
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Section 1"), new PageBreak(), new TextRun("Section 1"), new PageBreak()],
|
children: [new TextRun("Section 1"), new PageBreak(), new TextRun("Section 1"), new PageBreak()],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
},
|
||||||
|
{
|
||||||
doc.addSection({
|
properties: {
|
||||||
|
page: {
|
||||||
|
pageNumbers: {
|
||||||
|
start: 1,
|
||||||
|
formatType: PageNumberFormat.DECIMAL,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
headers: {
|
headers: {
|
||||||
default: header,
|
default: header,
|
||||||
},
|
},
|
||||||
footers: {
|
footers: {
|
||||||
default: footer,
|
default: footer,
|
||||||
},
|
},
|
||||||
properties: {
|
|
||||||
pageNumberStart: 1,
|
|
||||||
pageNumberFormatType: PageNumberFormat.DECIMAL,
|
|
||||||
},
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Section 2"), new PageBreak(), new TextRun("Section 2"), new PageBreak()],
|
children: [new TextRun("Section 2"), new PageBreak(), new TextRun("Section 2"), new PageBreak()],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, SectionVerticalAlignValue, TextRun } from "../build";
|
import { Document, Packer, Paragraph, SectionVerticalAlignValue, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
properties: {
|
properties: {
|
||||||
verticalAlign: SectionVerticalAlignValue.CENTER,
|
verticalAlign: SectionVerticalAlignValue.CENTER,
|
||||||
},
|
},
|
||||||
@ -24,6 +24,8 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,15 +1,47 @@
|
|||||||
// Add custom borders to the table itself
|
// Add custom borders and no-borders to the table itself
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { BorderStyle, Document, Packer, Paragraph, Table, TableCell, TableRow } from "../build";
|
import {
|
||||||
|
BorderStyle,
|
||||||
const doc = new Document();
|
Document,
|
||||||
|
HeadingLevel,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
Table,
|
||||||
|
TableBorders,
|
||||||
|
TableCell,
|
||||||
|
TableRow,
|
||||||
|
TextDirection,
|
||||||
|
VerticalAlign,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
new TableCell({
|
new TableCell({
|
||||||
|
borders: {
|
||||||
|
top: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
style: BorderStyle.DASH_SMALL_GAP,
|
||||||
|
size: 1,
|
||||||
|
color: "red",
|
||||||
|
},
|
||||||
|
},
|
||||||
children: [new Paragraph("Hello")],
|
children: [new Paragraph("Hello")],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
@ -30,7 +62,105 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({ children: [table] });
|
// Using the no-border convenience object. It is the same as writing this manually:
|
||||||
|
// const borders = {
|
||||||
|
// top: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// bottom: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// left: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// right: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// insideHorizontal: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// insideVertical: {
|
||||||
|
// style: BorderStyle.NONE,
|
||||||
|
// size: 0,
|
||||||
|
// color: "auto",
|
||||||
|
// },
|
||||||
|
// };
|
||||||
|
const noBorderTable = new Table({
|
||||||
|
borders: TableBorders.NONE,
|
||||||
|
rows: [
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({}), new Paragraph({})],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({}), new Paragraph({})],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({ text: "bottom to top" }), new Paragraph({})],
|
||||||
|
textDirection: TextDirection.BOTTOM_TO_TOP_LEFT_TO_RIGHT,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [new Paragraph({ text: "top to bottom" }), new Paragraph({})],
|
||||||
|
textDirection: TextDirection.TOP_TO_BOTTOM_RIGHT_TO_LEFT,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableRow({
|
||||||
|
children: [
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text:
|
||||||
|
"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",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "This text should be in the middle of the cell",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Text above should be vertical from bottom to top",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
new TableCell({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Text above should be vertical from top to bottom",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [{ children: [table, new Paragraph("Hello"), noBorderTable] }],
|
||||||
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
124
demo/5-images.ts
124
demo/5-images.ts
@ -1,27 +1,99 @@
|
|||||||
// Example of how to add images to the document - You can use Buffers, UInt8Arrays or Base64 strings
|
// Example of how to add images to the document - You can use Buffers, UInt8Arrays or Base64 strings
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
// import { Document, Packer, Paragraph } from "../build";
|
|
||||||
import {
|
import {
|
||||||
Document,
|
Document,
|
||||||
HorizontalPositionAlign,
|
HorizontalPositionAlign,
|
||||||
HorizontalPositionRelativeFrom,
|
HorizontalPositionRelativeFrom,
|
||||||
Media,
|
ImageRun,
|
||||||
Packer,
|
Packer,
|
||||||
Paragraph,
|
Paragraph,
|
||||||
VerticalPositionAlign,
|
VerticalPositionAlign,
|
||||||
VerticalPositionRelativeFrom,
|
VerticalPositionRelativeFrom,
|
||||||
} from "../build";
|
} from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
{
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/dog.png").toString("base64"));
|
children: [
|
||||||
const image3 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"));
|
new Paragraph("Hello World"),
|
||||||
const image4 = Media.addImage(doc, fs.readFileSync("./demo/images/parrots.bmp"));
|
new Paragraph({
|
||||||
const image5 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
children: [
|
||||||
const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/dog.png").toString("base64"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/cat.jpg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
flip: {
|
||||||
|
vertical: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/parrots.bmp"),
|
||||||
|
transformation: {
|
||||||
|
width: 150,
|
||||||
|
height: 150,
|
||||||
|
flip: {
|
||||||
|
horizontal: true,
|
||||||
|
},
|
||||||
|
rotation: 225,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
flip: {
|
||||||
|
horizontal: true,
|
||||||
|
vertical: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
rotation: 45,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
|
zIndex: 10,
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
offset: 1014400,
|
offset: 1014400,
|
||||||
},
|
},
|
||||||
@ -29,10 +101,19 @@ const image6 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 2
|
|||||||
offset: 1014400,
|
offset: 1014400,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
],
|
||||||
const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200, 200, {
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/cat.jpg"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
|
zIndex: 5,
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
relative: HorizontalPositionRelativeFrom.PAGE,
|
relative: HorizontalPositionRelativeFrom.PAGE,
|
||||||
align: HorizontalPositionAlign.RIGHT,
|
align: HorizontalPositionAlign.RIGHT,
|
||||||
@ -42,18 +123,11 @@ const image7 = Media.addImage(doc, fs.readFileSync("./demo/images/cat.jpg"), 200
|
|||||||
align: VerticalPositionAlign.BOTTOM,
|
align: VerticalPositionAlign.BOTTOM,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
],
|
||||||
doc.addSection({
|
}),
|
||||||
children: [
|
],
|
||||||
new Paragraph("Hello World"),
|
},
|
||||||
new Paragraph(image1),
|
|
||||||
new Paragraph(image2),
|
|
||||||
new Paragraph(image3),
|
|
||||||
new Paragraph(image4),
|
|
||||||
new Paragraph(image5),
|
|
||||||
new Paragraph(image6),
|
|
||||||
new Paragraph(image7),
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,19 +1,26 @@
|
|||||||
// Simple example to add text to a document
|
// The demo on the README.md
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, Media, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build";
|
import { Document, HeadingLevel, ImageRun, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg"));
|
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
rows: [
|
rows: [
|
||||||
new TableRow({
|
new TableRow({
|
||||||
children: [
|
children: [
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [new Paragraph(image1)],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
verticalAlign: VerticalAlign.CENTER,
|
verticalAlign: VerticalAlign.CENTER,
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
@ -38,21 +45,47 @@ const table = new Table({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
new TableCell({
|
new TableCell({
|
||||||
children: [new Paragraph(image1)],
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "Hello World",
|
text: "Hello World",
|
||||||
heading: HeadingLevel.HEADING_1,
|
heading: HeadingLevel.HEADING_1,
|
||||||
}),
|
}),
|
||||||
table,
|
table,
|
||||||
new Paragraph(image2),
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -15,11 +15,18 @@ const doc = new Document({
|
|||||||
italics: true,
|
italics: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "strong",
|
||||||
|
name: "Strong",
|
||||||
|
basedOn: "Normal",
|
||||||
|
run: {
|
||||||
|
bold: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -29,6 +36,20 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun({
|
||||||
|
text: "First Word",
|
||||||
|
style: "strong",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text:
|
||||||
|
" - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -18,9 +18,8 @@ const doc = new Document({
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "KFCを食べるのが好き",
|
text: "KFCを食べるのが好き",
|
||||||
@ -30,6 +29,8 @@ doc.addSection({
|
|||||||
text: "こんにちは",
|
text: "こんにちは",
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -11,6 +11,18 @@ import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
|||||||
|
|
||||||
const doc = new Document({
|
const doc = new Document({
|
||||||
styles: {
|
styles: {
|
||||||
|
default: {
|
||||||
|
document: {
|
||||||
|
run: {
|
||||||
|
font: {
|
||||||
|
ascii: "minorHAnsi",
|
||||||
|
eastAsia: "minorEastAsia",
|
||||||
|
cs: "minorBidi",
|
||||||
|
hAnsi: "minorHAnsi",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
paragraphStyles: [
|
paragraphStyles: [
|
||||||
{
|
{
|
||||||
id: "Normal",
|
id: "Normal",
|
||||||
@ -20,16 +32,17 @@ const doc = new Document({
|
|||||||
quickFormat: true,
|
quickFormat: true,
|
||||||
run: {
|
run: {
|
||||||
font: {
|
font: {
|
||||||
ascii: "Times",
|
ascii: "minorHAnsi", // Can also use minorHAnsi
|
||||||
eastAsia: "KaiTi",
|
eastAsia: "minorEastAsia", // Can also use minorEastAsia
|
||||||
|
cs: "minorBidi",
|
||||||
|
hAnsi: "minorHAnsi",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
sections: [
|
||||||
|
{
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
text: "中文和英文 Chinese and English",
|
text: "中文和英文 Chinese and English",
|
||||||
@ -47,6 +60,29 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: `店様付旅母正役基社発破班。発治治京岡局本因追意金紀統責郵滴尽。立功日庁重天富評界明済不着法返祉経正引行。載区列防新目治日群付無人道言越名。界安無死専体風木人教録覧訃。女問堂容県作先芸便効証帯債土全極的日。能山中岡仕関攻井季接店線幌温後率事阜止。成間路行究今式歌像祉帯式媛読徹。安行息古入出文侵監株登部席内文第珍鶴問用。
|
||||||
|
|
||||||
|
編竹入俳多応日氏陸福芸北供動。情績拠僧肺軍油能認郷翌南対韓短東食束兵晶。政予任習口佐所当止市告号。悩申無式立医毎部観潟訴菱権。発臼背郎上予配光記芸注然出。梨場株以政囲下球品材県動政押婚面見。米共試使落帳遅毅間三子開。問与大八地芸第線体架辺今死。押構草齢戦重最変社豪記目盗連報準周込。系貸劇様重鷲始能質村異社学動導勤。
|
||||||
|
|
||||||
|
残様的荻仲刺局標績供質球就雄。考和母問者役尊紙推新経革個事編安観。益学北日著楽車山勢流泉四犯投台戒設対臨百。危謄初治穴委済本索労刊回。月写政覧女事棋違年終索情響白子泉転企堀社。江遊著西高開面毎分芸責成創査全判調目止懇。原育会夏作売望人転乱融抜心。制川供健水示囲阜厚高右断季人役。持面必日暮気管像冬間影図健行格阪。
|
||||||
|
|
||||||
|
来入工速会健評下町慮大貸社一見園外申憶。服豊舞入面沢交使奥見記写意岩。北観提女刊液城共五擦相売田合是由読。回歳売苦定記点郎意増賛治北渡本応。受送文携村陸情静了申注際。順負子研済老上変女産第内無費携投展達。東初乗回動合語学待聴暮沢流全場導敷記賞次。更物中備著後渡売第部時禁新田木下昨。備護起織服久権意全海馬適応。
|
||||||
|
|
||||||
|
幸速団供地信討川安矛場消学年。去茂玉東今要出約元教負限載始今簡。編掲証的情仕渡室手映法部始。紙反語清阪曜税受知選謝個印観聞。教人超死準無者参生撤技真価椿景破市見国。左需臓道力趣暮際丁高会近部敗岡力当社。壊態毒期波超長写島断兆国世行共絞私報。反野番点図択女撃脱案情王援。減属考論月院催者門料約覧市戦。
|
||||||
|
|
||||||
|
山部午金査投立集争教殺巣作世動北部応。通負考隙問粛中帯閉要程規化小。橋棋互界時引就現省竹去子無系容米。竹転起日本新田強済購書区庁集作容同会窓教。文公神転待究挙登投川選囲針能楽路断出歌。祥新現寄公史真玉属元始員金抜関前百衝能。国眺暮囲世嘘面外営国内報夜九掲事春葉。来月刊台先良理著自供法投。通渡請当月学安首一押実展介況。
|
||||||
|
|
||||||
|
法優分独込右得里記域目順供進乗。憂婚転峰大写医投社曲題任能務熱県展覧港専。栄余歯真著改追事作果石芸。青感将南便再転領鈴投提鉄索競虎師体物想。牲打迎達携度開技書催掲安去変念座。革混疑生採就枢当住回県組北意寛。爆新和級掲交象温十賛展木開有結日。新海辺小除京物興量写界裁上。文師建関面取質也底沼画者図空医心無季。
|
||||||
|
|
||||||
|
高館湯転名気業以際置講詰方活礎組調軽際。発変東作訪乃小化理利提目気。極季本問号面帯勤戦行新禁情堀郎携。座所転再祥業必変昌今歩佐王立抗後養崩。支物猪躍芸整縦焦供防続相護治時語朝分刊定。綿田幸崎責本欲間載神調崎答志政報与速美載。飯治止稿原先明画森群進見情幕。女民館終調質並伝車慌供科。支田国傷自動献疑討医足公成公主断的望。
|
||||||
|
|
||||||
|
責開児食福実帰治師今策今。水重寺圧医観送連東者秒途。選央力律式開作掲写様階組戦写型紙。式国販時天遣国出難共前次領体康稲住転。査見保重議原速群者内月正連。爾天膨装芸別巨平運数準三浜念載創県奈飛提。素京発揮田談気党示見象定電類代級。善返跡国有話権入猛府週亡辞馬脳。関残主祐雪塚去集村完海関文受載表川護照立。
|
||||||
|
|
||||||
|
発闘美慎健育旅布容広互無秋認天歌媛芸。転器合読県増認会賞倒点系。食気母服絵知去祝芸車報熱勝。能貿月更障文的欠賞現覇声敏施会。懲病写昼法族業律記聡生開緊楽暮護。東地二員者説盟治害討面提。第北乗査庭年近的禁疑報方店記必迷都流通。聞有力前愛院梨野関業前訳本清滋補。蒲読火死勝広保会婚際気二由保国。用君込村需起相点選紙拡氏訃不。`,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
27
demo/54-custom-properties.ts
Normal file
27
demo/54-custom-properties.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
// Custom Properties
|
||||||
|
// Custom properties are incredibly useful if you want to be able to apply quick parts or custom cover pages
|
||||||
|
// to the document in Word after the document has been generated. Standard properties (such as creator, title
|
||||||
|
// and subject) cover typical use cases, but sometimes custom properties are required.
|
||||||
|
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document(
|
||||||
|
// Standard properties
|
||||||
|
{
|
||||||
|
creator: "Creator",
|
||||||
|
title: "Title",
|
||||||
|
subject: "Subject",
|
||||||
|
description: "Description",
|
||||||
|
customProperties: [
|
||||||
|
{ name: "Subtitle", value: "Subtitle" },
|
||||||
|
{ name: "Address", value: "Address" },
|
||||||
|
],
|
||||||
|
sections: [],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
296
demo/55-math.ts
Normal file
296
demo/55-math.ts
Normal file
@ -0,0 +1,296 @@
|
|||||||
|
// 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,
|
||||||
|
Math,
|
||||||
|
MathAngledBrackets,
|
||||||
|
MathCurlyBrackets,
|
||||||
|
MathFraction,
|
||||||
|
MathFunction,
|
||||||
|
MathPreSubSuperScript,
|
||||||
|
MathRadical,
|
||||||
|
MathRoundBrackets,
|
||||||
|
MathRun,
|
||||||
|
MathSquareBrackets,
|
||||||
|
MathSubScript,
|
||||||
|
MathSubSuperScript,
|
||||||
|
MathSum,
|
||||||
|
MathSuperScript,
|
||||||
|
Packer,
|
||||||
|
Paragraph,
|
||||||
|
TextRun,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRun("2+2"),
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("hi")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [
|
||||||
|
new MathRun("1"),
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSum({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
}),
|
||||||
|
new MathSum({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
new MathSum({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
subScript: [new MathRun("hello")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
subScript: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("y")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
subScript: [new MathRun("world")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathPreSubSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
subScript: [new MathRun("world")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathSubScript({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
degree: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("x")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFunction({
|
||||||
|
name: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("cos")],
|
||||||
|
superScript: [new MathRun("-1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
children: [new MathRun("100")],
|
||||||
|
}),
|
||||||
|
new MathRun("×"),
|
||||||
|
new MathFunction({
|
||||||
|
name: [new MathRun("sin")],
|
||||||
|
children: [new MathRun("360")],
|
||||||
|
}),
|
||||||
|
new MathRun("= x"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRoundBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new MathSquareBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new MathCurlyBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new MathAngledBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("4")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
denominator: [new MathRun("2a")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
34
demo/56-background-color.ts
Normal file
34
demo/56-background-color.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// Change background colour of whole document
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
background: {
|
||||||
|
color: "C45911",
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
89
demo/57-add-parent-numbered-lists.ts
Normal file
89
demo/57-add-parent-numbered-lists.ts
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
// Numbered lists - Add parent number in sub number
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { AlignmentType, convertInchesToTwip, Document, HeadingLevel, LevelFormat, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
numbering: {
|
||||||
|
config: [
|
||||||
|
{
|
||||||
|
levels: [
|
||||||
|
{
|
||||||
|
level: 0,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: convertInchesToTwip(0.5), hanging: 260 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
level: 1,
|
||||||
|
format: LevelFormat.DECIMAL,
|
||||||
|
text: "%1.%2",
|
||||||
|
alignment: AlignmentType.START,
|
||||||
|
style: {
|
||||||
|
paragraph: {
|
||||||
|
indent: { left: 1.25 * convertInchesToTwip(0.5), hanging: 1.25 * 260 },
|
||||||
|
},
|
||||||
|
run: {
|
||||||
|
bold: true,
|
||||||
|
size: 18,
|
||||||
|
font: "Times New Roman",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "How to make cake",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 1 - Add sugar",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 2 - Add wheat",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 2a - Stir the wheat in a circle",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 1,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Step 3 - Put in oven",
|
||||||
|
numbering: {
|
||||||
|
reference: "my-number-numbering-reference",
|
||||||
|
level: 0,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "How to make cake",
|
||||||
|
heading: HeadingLevel.HEADING_1,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
91
demo/58-section-types.ts
Normal file
91
demo/58-section-types.ts
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
// Usage of different Section Types
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Packer, Paragraph, TextRun, SectionType } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.CONTINUOUS,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.ODD_PAGE,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.EVEN_PAGE,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.NEXT_PAGE,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
54
demo/59-header-footer-margins.ts
Normal file
54
demo/59-header-footer-margins.ts
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Move + offset header and footer
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
|
margin: {
|
||||||
|
header: 100,
|
||||||
|
footer: 50,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Header text",
|
||||||
|
indent: {
|
||||||
|
left: -400,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Some more header text",
|
||||||
|
indent: {
|
||||||
|
left: -600,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Footer text",
|
||||||
|
indent: {
|
||||||
|
left: -400,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [new Paragraph("Hello World")],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -3,15 +3,19 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
import { Document, HeadingLevel, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
margins: {
|
properties: {
|
||||||
|
page: {
|
||||||
|
margin: {
|
||||||
top: 0,
|
top: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -33,6 +37,8 @@ doc.addSection({
|
|||||||
new Paragraph("Foo bar"),
|
new Paragraph("Foo bar"),
|
||||||
new Paragraph("Github is the best"),
|
new Paragraph("Github is the best"),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
151
demo/60-track-revisions.ts
Normal file
151
demo/60-track-revisions.ts
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
// Track Revisions aka. "Track Changes"
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import {
|
||||||
|
AlignmentType,
|
||||||
|
DeletedTextRun,
|
||||||
|
Document,
|
||||||
|
Footer,
|
||||||
|
FootnoteReferenceRun,
|
||||||
|
InsertedTextRun,
|
||||||
|
Packer,
|
||||||
|
PageNumber,
|
||||||
|
Paragraph,
|
||||||
|
ShadingType,
|
||||||
|
TextRun,
|
||||||
|
} from "../build";
|
||||||
|
|
||||||
|
/*
|
||||||
|
For reference, see
|
||||||
|
- https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.insertedrun
|
||||||
|
- https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.deletedrun
|
||||||
|
|
||||||
|
The method `addTrackRevisions()` adds an element `<w:trackRevisions />` to the `settings.xml` file. This specifies that the application shall track *new* revisions made to the existing document.
|
||||||
|
See also https://docs.microsoft.com/en-us/dotnet/api/documentformat.openxml.wordprocessing.trackrevisions
|
||||||
|
|
||||||
|
Note that this setting enables to track *new changes* after teh file is generated, so this example will still show inserted and deleted text runs when you remove it.
|
||||||
|
*/
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a simple demo "),
|
||||||
|
new TextRun({
|
||||||
|
text: "on how to ",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: "mark a text as an insertion ",
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: "or a deletion.",
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
footnotes: {
|
||||||
|
1: {
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a footnote"),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: " with some extra text which was deleted",
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: " and new content",
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
features: {
|
||||||
|
trackRevisions: true,
|
||||||
|
},
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
paragraph,
|
||||||
|
new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a demo "),
|
||||||
|
new DeletedTextRun({
|
||||||
|
break: 1,
|
||||||
|
text: "in order",
|
||||||
|
color: "red",
|
||||||
|
bold: true,
|
||||||
|
size: 24,
|
||||||
|
font: {
|
||||||
|
name: "Garamond",
|
||||||
|
},
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
id: 2,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: "to show how to ",
|
||||||
|
bold: false,
|
||||||
|
id: 3,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
bold: true,
|
||||||
|
children: ["\tuse Inserted and Deleted TextRuns.", new FootnoteReferenceRun(1)],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
alignment: AlignmentType.CENTER,
|
||||||
|
children: [
|
||||||
|
new TextRun("Awesome LLC"),
|
||||||
|
new TextRun({
|
||||||
|
children: ["Page Number: ", PageNumber.CURRENT],
|
||||||
|
}),
|
||||||
|
new DeletedTextRun({
|
||||||
|
children: [" to ", PageNumber.TOTAL_PAGES],
|
||||||
|
id: 4,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
children: [" from ", PageNumber.TOTAL_PAGES],
|
||||||
|
bold: true,
|
||||||
|
id: 5,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:05:00Z",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
73
demo/61-text-frame.ts
Normal file
73
demo/61-text-frame.ts
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
// Text Frame (Text Box) example
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, FrameAnchorType, HorizontalPositionAlign, Packer, Paragraph, TextRun, VerticalPositionAlign } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
frame: {
|
||||||
|
position: {
|
||||||
|
x: 1000,
|
||||||
|
y: 3000,
|
||||||
|
},
|
||||||
|
width: 4000,
|
||||||
|
height: 1000,
|
||||||
|
anchor: {
|
||||||
|
horizontal: FrameAnchorType.MARGIN,
|
||||||
|
vertical: FrameAnchorType.MARGIN,
|
||||||
|
},
|
||||||
|
alignment: {
|
||||||
|
x: HorizontalPositionAlign.CENTER,
|
||||||
|
y: VerticalPositionAlign.TOP,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
top: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
36
demo/62-paragraph-spacing.ts
Normal file
36
demo/62-paragraph-spacing.ts
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
// 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, LineRuleType, Packer, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
properties: {},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
spacing: {
|
||||||
|
after: 5000,
|
||||||
|
before: 5000,
|
||||||
|
},
|
||||||
|
children: [new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
spacing: {
|
||||||
|
line: 2000,
|
||||||
|
lineRule: LineRuleType.AUTO,
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun(
|
||||||
|
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed turpis ex, aliquet et faucibus quis, euismod in odio. Fusce gravida tempor nunc sed lacinia. Nulla sed dolor fringilla, fermentum libero ut, egestas ex. Donec pellentesque metus non orci lacinia bibendum. Cras porta ex et mollis hendrerit. Suspendisse id lectus suscipit, elementum lacus eu, convallis felis. Fusce sed bibendum dolor, id posuere ligula. Aliquam eu elit ut urna eleifend vestibulum. Praesent condimentum at turpis sed scelerisque. Suspendisse porttitor metus nec vestibulum egestas. Sed in eros sapien. Morbi efficitur placerat est a consequat. Nunc bibendum porttitor mi nec tempus. Morbi dictum augue porttitor nisi sodales sodales.",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
71
demo/63-odd-even-header-footer.ts
Normal file
71
demo/63-odd-even-header-footer.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
// Move + offset header and footer
|
||||||
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { Document, Footer, Header, Packer, PageBreak, Paragraph, TextRun } from "../build";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
evenAndOddHeaderAndFooters: true,
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
default: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Odd Header text",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Odd - Some more header text",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
even: new Header({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Even header text",
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Even - Some more header text",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
footers: {
|
||||||
|
default: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Odd Footer text",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
even: new Footer({
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
text: "Even Cool Footer text",
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 1"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 2"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 3"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 4"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World 5"), new PageBreak()],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
|
});
|
@ -3,13 +3,19 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, PageOrientation, Paragraph } from "../build";
|
import { Document, Packer, PageOrientation, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
|
properties: {
|
||||||
|
page: {
|
||||||
size: {
|
size: {
|
||||||
orientation: PageOrientation.LANDSCAPE,
|
orientation: PageOrientation.LANDSCAPE,
|
||||||
},
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
children: [new Paragraph("Hello World")],
|
children: [new Paragraph("Hello World")],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -3,9 +3,9 @@
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Footer, Header, Packer, Paragraph } from "../build";
|
import { Document, Footer, Header, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
doc.addSection({
|
{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [new Paragraph("Header text")],
|
children: [new Paragraph("Header text")],
|
||||||
@ -17,6 +17,8 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [new Paragraph("Hello World")],
|
children: [new Paragraph("Hello World")],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
// Add images to header and footer
|
// Add images to header and footer
|
||||||
// Import from 'docx' rather than '../build' if you install from npm
|
// Import from 'docx' rather than '../build' if you install from npm
|
||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Footer, Header, Media, Packer, Paragraph } from "../build";
|
import { Document, Footer, Header, ImageRun, Packer, Paragraph } from "../build";
|
||||||
|
|
||||||
const doc = new Document();
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
{
|
||||||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
|
||||||
|
|
||||||
doc.addSection({
|
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({
|
default: new Header({
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [image1],
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
@ -22,12 +27,22 @@ doc.addSection({
|
|||||||
default: new Footer({
|
default: new Footer({
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [image2],
|
children: [
|
||||||
|
new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [new Paragraph("Hello World")],
|
children: [new Paragraph("Hello World")],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
Packer.toBuffer(doc).then((buffer) => {
|
Packer.toBuffer(doc).then((buffer) => {
|
||||||
|
File diff suppressed because one or more lines are too long
@ -14,7 +14,9 @@
|
|||||||
function generate() {
|
function generate() {
|
||||||
const doc = new docx.Document();
|
const doc = new docx.Document();
|
||||||
|
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [
|
||||||
|
{
|
||||||
children: [
|
children: [
|
||||||
new docx.Paragraph({
|
new docx.Paragraph({
|
||||||
children: [
|
children: [
|
||||||
@ -30,10 +32,10 @@
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
docx.Packer.toBlob(doc).then((blob) => {
|
docx.Packer.toBlob(doc).then((blob) => {
|
||||||
console.log(blob);
|
console.log(blob);
|
||||||
saveAs(blob, "example.docx");
|
saveAs(blob, "example.docx");
|
||||||
|
@ -1,13 +1,3 @@
|
|||||||
<p align="center">
|
|
||||||
<img alt="clippy the assistant" src="https://i.imgur.com/37uBGhO.gif">
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
|
|
||||||
</p>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
# Welcome
|
# Welcome
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
@ -34,12 +24,10 @@ import { ... } from "docx";
|
|||||||
import * as fs from "fs";
|
import * as fs from "fs";
|
||||||
import { Document, Packer, Paragraph, TextRun } from "docx";
|
import { Document, Packer, Paragraph, TextRun } from "docx";
|
||||||
|
|
||||||
// Create document
|
|
||||||
const doc = new Document();
|
|
||||||
|
|
||||||
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
|
// Documents contain sections, you can have multiple sections per document, go here to learn more about sections
|
||||||
// This simple example will only contain one section
|
// This simple example will only contain one section
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
properties: {},
|
properties: {},
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
@ -56,6 +44,7 @@ doc.addSection({
|
|||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
|
|
||||||
// Used to export the file into a .docx file
|
// Used to export the file into a .docx file
|
||||||
@ -63,17 +52,11 @@ Packer.toBuffer(doc).then((buffer) => {
|
|||||||
fs.writeFileSync("My Document.docx", buffer);
|
fs.writeFileSync("My Document.docx", buffer);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Done! A file called 'My First Document.docx' will be in your file system.
|
// Done! A file called 'My Document.docx' will be in your file system.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Honoured Mentions
|
|
||||||
|
|
||||||
[@felipeochoa](https://github.com/felipeochoa)
|
|
||||||
|
|
||||||
[@h4buli](https://github.com/h4buli)
|
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img alt="clippy the assistant" src="http://i60.tinypic.com/339pvtt.png">
|
<img alt="clippy the assistant" src="./clippy.png">
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
---
|
---
|
||||||
|
10
docs/_coverpage.md
Normal file
10
docs/_coverpage.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<img src="https://i.imgur.com/37uBGhO.gif" alt="drawing" style="width:200px;"/>
|
||||||
|
|
||||||
|
> Easily generate .docx files with JS/TS. Works for Node and on the Browser. :100:
|
||||||
|
|
||||||
|
- Simple, declarative API
|
||||||
|
- 60+ usage examples
|
||||||
|
- Battle tested, mature, 98%+ coverage
|
||||||
|
|
||||||
|
[GitHub](https://github.com/dolanmiu/docx)
|
||||||
|
[Get Started](#Welcome)
|
@ -1,6 +1,6 @@
|
|||||||
* [Getting Started](/)
|
* [Getting Started](/)
|
||||||
|
|
||||||
* [Examples](examples.md)
|
* [Examples](https://github.com/dolanmiu/docx/tree/master/demo)
|
||||||
|
|
||||||
* API
|
* API
|
||||||
|
|
||||||
@ -20,12 +20,17 @@
|
|||||||
* [Tab Stops](usage/tab-stops.md)
|
* [Tab Stops](usage/tab-stops.md)
|
||||||
* [Table of Contents](usage/table-of-contents.md)
|
* [Table of Contents](usage/table-of-contents.md)
|
||||||
* [Page Numbers](usage/page-numbers.md)
|
* [Page Numbers](usage/page-numbers.md)
|
||||||
|
* [Change Tracking](usage/change-tracking.md)
|
||||||
|
* [Math](usage/math.md)
|
||||||
|
* [Text Frames](usage/text-frames.md)
|
||||||
* Styling
|
* Styling
|
||||||
* [Styling with JS](usage/styling-with-js.md)
|
* [Styling with JS](usage/styling-with-js.md)
|
||||||
* [Styling with XML](usage/styling-with-xml.md)
|
* [Styling with XML](usage/styling-with-xml.md)
|
||||||
* Exporting
|
* Exporting
|
||||||
|
|
||||||
* [Packers](usage/packers.md)
|
* [Packers](usage/packers.md)
|
||||||
|
* Utility
|
||||||
|
|
||||||
|
* [Convenience functions](usage/convenience-functions.md)
|
||||||
|
|
||||||
* [Contribution Guidelines](contribution-guidelines.md)
|
* [Contribution Guidelines](contribution-guidelines.md)
|
||||||
|
|
||||||
|
BIN
docs/clippy.png
Normal file
BIN
docs/clippy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
BIN
docs/clippy.psd
Normal file
BIN
docs/clippy.psd
Normal file
Binary file not shown.
@ -1,25 +1,23 @@
|
|||||||
# Contribution Guidelines
|
# Contribution Guidelines
|
||||||
|
|
||||||
* Include documentation reference(s) at the top of each file:
|
- Include documentation reference(s) at the top of each file:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
// http://officeopenxml.com/WPdocument.php
|
// http://officeopenxml.com/WPdocument.php
|
||||||
```
|
```
|
||||||
|
|
||||||
* Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
- Follow Prettier standards, and consider using the [Prettier VSCode](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) plugin.
|
||||||
|
|
||||||
* Follow the `TSLint` rules
|
- Follow the `TSLint` rules
|
||||||
|
|
||||||
## Always think about the user
|
## Always think about the user
|
||||||
|
|
||||||
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.
|
Put yourself in their position, and imagine how they would feel about your feature you wrote.
|
||||||
|
|
||||||
1. Is it easy to use?
|
1. Is it easy to use?
|
||||||
2. Has it been documented well?
|
2. Has it been documented well?
|
||||||
3. Is it intuitive?
|
3. Is it intuitive?
|
||||||
4. Is it consistent with the rest of the API?
|
4. Is it declarative?
|
||||||
5. Is it fun to use?
|
5. Is it fun to use?
|
||||||
|
|
||||||
## Good Commit Names
|
## Good Commit Names
|
||||||
@ -27,6 +25,7 @@ Put yourself in their position, and imagine how they would feel about your featu
|
|||||||
Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/
|
Please write good commit messages when making a commit: https://chris.beams.io/posts/git-commit/
|
||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
```
|
```
|
||||||
c // What?
|
c // What?
|
||||||
rtl // Adding acryonyms without explaining anything else is not helpful
|
rtl // Adding acryonyms without explaining anything else is not helpful
|
||||||
@ -35,34 +34,6 @@ demo updated // Getting better, but capitalize the first letter
|
|||||||
Unesesary coment removed // Make sure to use correct spelling
|
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.
|
|
||||||
|
|
||||||
Try to make method parameters of the outside API accept primitives, 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 for the end user, no need for:
|
|
||||||
```ts
|
|
||||||
import { ChildComponent } from "./my-feature/sub-component/deeper/.../my-deep.component";
|
|
||||||
```
|
|
||||||
|
|
||||||
2. This is what I consider "leakage". The code is aware of the underlying implementation of the component.
|
|
||||||
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 `new` up the object, and inject it in like so:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
public float(tableFloatProperties: TableFloatProperties): Table
|
|
||||||
```
|
|
||||||
|
|
||||||
```ts
|
|
||||||
table.float(new TableFloatProperties(...));
|
|
||||||
```
|
|
||||||
|
|
||||||
**Do**
|
**Do**
|
||||||
|
|
||||||
`ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals:
|
`ITableFloatOptions` is an interface for a JSON of primitives. The end user would need to pass in a json object and not need to worry about the internals:
|
||||||
@ -71,30 +42,30 @@ This is so that:
|
|||||||
public float(tableFloatOptions: ITableFloatOptions): Table
|
public float(tableFloatOptions: ITableFloatOptions): Table
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Delcariative API
|
||||||
|
|
||||||
|
Make sure the API is declarative, so no _method calling_ or _mutation_. This is a design decision, consistent with the rest of the project. There are benefits to delcariative code over other styles of code, explained here: https://dzone.com/articles/why-declarative-coding-makes-you-a-better-programm
|
||||||
|
|
||||||
|
**Do not:**
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
table.float({...});
|
const paragraph = doc.createParagraph();
|
||||||
|
const text = paragraph.createText();
|
||||||
|
text.contents = "Hello World";
|
||||||
```
|
```
|
||||||
|
|
||||||
## Add vs Create
|
**Do**
|
||||||
|
|
||||||
This is just a guideline, and the rules can sometimes be broken.
|
|
||||||
|
|
||||||
* Use `create` if the method `new`'s up an element inside:
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
public createParagraph() {
|
const doc = new Document({
|
||||||
const paragraph = new Paragraph();
|
sections: [{
|
||||||
this.root.push(paragraph);
|
children: [
|
||||||
}
|
new Paragraph({
|
||||||
```
|
children: [new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
* 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:
|
}];
|
||||||
|
});
|
||||||
```ts
|
|
||||||
public add(paragraph: Paragraph) {
|
|
||||||
this.root.push(paragraph);
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Getters and Setters
|
## Getters and Setters
|
||||||
@ -107,7 +78,7 @@ public get Level() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
There is no performance advantage by doing this. It means we don't need to prefix all private variables with the ugly `_`:
|
This is the convention of this project. There is no performance advantage by doing this. It means we don't need to prefix all private variables with `_`:
|
||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
@ -121,30 +92,6 @@ private get _level: string;
|
|||||||
private get level: string;
|
private get level: string;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Temporal Methods
|
|
||||||
|
|
||||||
Some methods are `non-temporal`, which means regardless of when you call the method, it will have the same affect on the document. For example, setting the width of a table at the end of the document will have the same effect as setting the width at the start:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
table.setWidth(1000); // now removed as of version 5.0.0
|
|
||||||
```
|
|
||||||
|
|
||||||
Whereas some methods are `temporal`, which means depending on the time-frame they are called, it would produce a difference result. For example, moving `createParagraph()` around your code will physically alter the document.
|
|
||||||
|
|
||||||
```ts
|
|
||||||
doc.createParagraph("hello");
|
|
||||||
```
|
|
||||||
|
|
||||||
If a method is `non-temporal`, put it in the objects `constructor`. For example:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const table = new Table(width: number);
|
|
||||||
```
|
|
||||||
|
|
||||||
`Non-temporal` methods are usually methods which can only be used one time and one time only. For example, `.float()`. It does not make sense to call `.float()` again if its already floating.
|
|
||||||
|
|
||||||
I am not sure what the real term is, but this will do.
|
|
||||||
|
|
||||||
## Interfaces over type alias
|
## Interfaces over type alias
|
||||||
|
|
||||||
Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it.
|
Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a class cannot implement it.
|
||||||
@ -152,14 +99,14 @@ Do not use `type`, but rather use `Interfaces`. `type` cannot be extended, and a
|
|||||||
> "In general, use what you want ( type alias / interface ) just be consistent"
|
> "In general, use what you want ( type alias / interface ) just be consistent"
|
||||||
> "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions"
|
> "always use interface for public API's definition when authoring a library or 3rd party ambient type definitions"
|
||||||
>
|
>
|
||||||
> * https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
|
> - https://medium.com/@martin_hotell/interface-vs-type-alias-in-typescript-2-7-2a8f1777af4c
|
||||||
|
|
||||||
`Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types
|
`Interface` is generally preferred over `type`: https://stackoverflow.com/questions/37233735/typescript-interfaces-vs-types
|
||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
type RelationshipFileInfo = { id: number, target: string };
|
type RelationshipFileInfo = { id: number; target: string };
|
||||||
```
|
```
|
||||||
|
|
||||||
**Do:**
|
**Do:**
|
||||||
@ -193,26 +140,26 @@ enum WeaponType = {
|
|||||||
|
|
||||||
## Spell correctly, in full and in American English
|
## Spell correctly, in full and in American English
|
||||||
|
|
||||||
I am not sure where these habits in software development come from, but I do not believe it is beneficial:
|
|
||||||
|
|
||||||
**Do not:**
|
**Do not:**
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
readdy // misspelling
|
readdy; // misspelling
|
||||||
perm // abbreviation
|
perm; // abbreviation
|
||||||
conf // abbreviation
|
conf; // abbreviation
|
||||||
cnty // abbreviation
|
cnty; // abbreviation
|
||||||
relationFile // abbreviation
|
relationFile; // abbreviation
|
||||||
colour // U.K. English
|
colour; // U.K. English
|
||||||
```
|
```
|
||||||
|
|
||||||
**Do:**
|
**Do:**
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
ready
|
ready;
|
||||||
permission
|
permission;
|
||||||
config
|
config;
|
||||||
country
|
country;
|
||||||
relationshipFile
|
relationshipFile;
|
||||||
color
|
color;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Keep files small (within reason)
|
## Keep files small (within reason)
|
||||||
|
219
docs/examples.md
219
docs/examples.md
@ -1,219 +0,0 @@
|
|||||||
# Examples
|
|
||||||
|
|
||||||
> All examples can run independently and can be found in the `/demo` folder of the project
|
|
||||||
|
|
||||||
All the examples below can be ran locally, to do so, run the following command:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm run demo
|
|
||||||
```
|
|
||||||
|
|
||||||
This command will run the `demo selector app` in the `/demo` folder. It will prompt you to select a demo number, which will run a demo from that folder.
|
|
||||||
|
|
||||||
## Simple
|
|
||||||
|
|
||||||
A simple hello world of the `docx` library:
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo1.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.ts_
|
|
||||||
|
|
||||||
## Styles
|
|
||||||
|
|
||||||
### Styling with JS
|
|
||||||
|
|
||||||
This example shows how to customise the look and feel of a document using JS configuration
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo2.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.ts_
|
|
||||||
|
|
||||||
### Styling with XML
|
|
||||||
|
|
||||||
This example shows how to customise the look and feel of a document using XML configuration
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo13.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.ts_
|
|
||||||
|
|
||||||
## Numbering
|
|
||||||
|
|
||||||
This example shows many levels of numbering
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo3.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.ts_
|
|
||||||
|
|
||||||
## Table
|
|
||||||
|
|
||||||
Example of simple table
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo4.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.ts_
|
|
||||||
|
|
||||||
### Styling table borders
|
|
||||||
|
|
||||||
Styling the borders of a table
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo20.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.ts_
|
|
||||||
|
|
||||||
## Images
|
|
||||||
|
|
||||||
### Add image to the document
|
|
||||||
|
|
||||||
Importing Images from file system path
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo5.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.ts_
|
|
||||||
|
|
||||||
### Add images to header and footer
|
|
||||||
|
|
||||||
Example showing how to add image to headers and footers
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo9.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.ts_
|
|
||||||
|
|
||||||
### Scaling images
|
|
||||||
|
|
||||||
Example showing how to scale images
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo12.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.ts_
|
|
||||||
|
|
||||||
### Add Image to media before adding to document
|
|
||||||
|
|
||||||
This is the best way to add an image to a document because you can add the same image in two locations without increasing document size by re-using the same image
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo23.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.ts_
|
|
||||||
|
|
||||||
### Add image to table
|
|
||||||
|
|
||||||
As before, to add an image to a table, you would need to add it to the `Media` object first
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo24.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.ts_
|
|
||||||
|
|
||||||
### Images using Base64 URI
|
|
||||||
|
|
||||||
If you want to use a Base64 image instead
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo18.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
|
|
||||||
|
|
||||||
## Margins
|
|
||||||
|
|
||||||
Example showing how to set custom margins
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.ts_
|
|
||||||
|
|
||||||
## Orientation
|
|
||||||
|
|
||||||
Example showing how to set the document to `landscape` or `portrait`
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo7.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.ts_
|
|
||||||
|
|
||||||
## Headers & Footers
|
|
||||||
|
|
||||||
Example showing how to add headers and footers
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo8.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.ts_
|
|
||||||
|
|
||||||
## Multiple headers and footers
|
|
||||||
|
|
||||||
Check out `Sections` for this feature
|
|
||||||
|
|
||||||
## Page Breaks
|
|
||||||
|
|
||||||
### Normal page breaks
|
|
||||||
|
|
||||||
Example showing how to page break
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo14.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.ts_
|
|
||||||
|
|
||||||
### Page break before
|
|
||||||
|
|
||||||
Example showing how to page break before like in Word
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo15.ts ':include')
|
|
||||||
|
|
||||||
_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.
|
|
||||||
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')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.ts_
|
|
||||||
|
|
||||||
## Footnotes
|
|
||||||
|
|
||||||
Example of how to add footnotes. Good for references
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo17.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.ts_
|
|
||||||
|
|
||||||
## Packers
|
|
||||||
|
|
||||||
## Buffer output
|
|
||||||
|
|
||||||
Example showing how to use the Buffer packer and then write that buffer to the file system
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo19.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.ts_
|
|
||||||
|
|
||||||
|
|
||||||
## Bookmarks
|
|
||||||
|
|
||||||
Example showing how to make bookmarks to make internal hyperlinks within the document
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo21.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.ts_
|
|
||||||
|
|
||||||
## Bidirectional text
|
|
||||||
|
|
||||||
Example showing how to use bidirectional text for certain languages such as Hebrew
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo22.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.ts_
|
|
||||||
|
|
||||||
## Showcase
|
|
||||||
|
|
||||||
### My CV
|
|
||||||
|
|
||||||
Example showing how to add headers and footers
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo10.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.ts_
|
|
||||||
|
|
||||||
### Style and Images
|
|
||||||
|
|
||||||
This example shows how to customise the look and feel of a document and add images
|
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo11.ts ':include')
|
|
||||||
|
|
||||||
_Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.ts_
|
|
BIN
docs/images/math-example.png
Normal file
BIN
docs/images/math-example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
@ -1,12 +1,11 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8" />
|
||||||
<title>docx - Generate .docx documents with JavaScript</title>
|
<title>docx - Generate .docx documents with JavaScript</title>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
||||||
<meta name="description" content="Generate .docx documents with JavaScript">
|
<meta name="description" content="Generate .docx documents with JavaScript" />
|
||||||
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
|
href="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/style.min.css"
|
||||||
@ -19,22 +18,19 @@
|
|||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
<script>
|
<script>
|
||||||
window.$docsify = {
|
window.$docsify = {
|
||||||
name: 'docx',
|
name: "docx",
|
||||||
repo: 'https://github.com/dolanmiu/docx',
|
repo: "https://github.com/dolanmiu/docx",
|
||||||
loadSidebar: true,
|
loadSidebar: true,
|
||||||
subMaxLevel: 2,
|
subMaxLevel: 2,
|
||||||
search: 'auto',
|
search: "auto",
|
||||||
}
|
coverpage: true,
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/docsify.min.js"></script>
|
||||||
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/plugins/emoji.min.js"></script>
|
||||||
<script src="https://unpkg.com/docsify-copy-code@2"></script>
|
<script src="https://unpkg.com/docsify-copy-code@2"></script>
|
||||||
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
<script src="//unpkg.com/docsify/lib/plugins/search.min.js"></script>
|
||||||
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
|
<script src="//unpkg.com/prismjs/components/prism-typescript.min.js"></script>
|
||||||
<script
|
<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>
|
||||||
src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js"
|
|
||||||
type="text/javascript">
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,16 +1,28 @@
|
|||||||
# Bullet Points
|
# Bullet Points
|
||||||
|
|
||||||
|
!> Bullet Points requires an understanding of [Paragraphs](usage/paragraph.md).
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
To make a bullet point, simply make a paragraph into a bullet point:
|
To make a bullet point, simply make a paragraph into a bullet point:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const text = new TextRun("Bullet points");
|
const doc = new Document({
|
||||||
const paragraph = new Paragraph({
|
sections: [{
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
text: "Bullet points",
|
text: "Bullet points",
|
||||||
bullet: {
|
bullet: {
|
||||||
level: 0, // How deep you want the bullet to me
|
level: 0 //How deep you want the bullet to be
|
||||||
},
|
}
|
||||||
|
}),
|
||||||
|
new Paragraph({
|
||||||
|
text: "Are awesome",
|
||||||
|
bullet: {
|
||||||
|
level: 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
61
docs/usage/change-tracking.md
Normal file
61
docs/usage/change-tracking.md
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
# Change Tracking
|
||||||
|
|
||||||
|
> Instead of adding a `TextRun` into a `Paragraph`, you can also add an `InsertedTextRun` or `DeletedTextRun` where you need to supply an `id`, `author` and `date` for the change.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx";
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a simple demo "),
|
||||||
|
new TextRun({
|
||||||
|
text: "on how to "
|
||||||
|
}),
|
||||||
|
new InsertedTextRun({
|
||||||
|
text: "mark a text as an insertion ",
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
}),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: "or a deletion.",
|
||||||
|
id: 1,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
})
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that for a `InsertedTextRun` and `DeletedTextRun`, it is not possible to simply call it with only a text as in `new TextRun("some text")`, since the additonal fields for change tracking need to be provided. Similar to a normal `TextRun` you can add additional text properties.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Paragraph, TextRun, InsertedTextRun, DeletedTextRun } from "docx";
|
||||||
|
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
children: [
|
||||||
|
new TextRun("This is a simple demo"),
|
||||||
|
new DeletedTextRun({
|
||||||
|
text: "with a deletion.",
|
||||||
|
color: "red",
|
||||||
|
bold: true,
|
||||||
|
size: 24,
|
||||||
|
id: 0,
|
||||||
|
author: "Firstname Lastname",
|
||||||
|
date: "2020-10-06T09:00:00Z",
|
||||||
|
})
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
In addtion to marking text as inserted or deleted, change tracking can also be added via the document settings. This will enable new changes to be tracked as well.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { Document } from "docx";
|
||||||
|
|
||||||
|
const doc = new Document({
|
||||||
|
features: {
|
||||||
|
trackRevisions: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
22
docs/usage/convenience-functions.md
Normal file
22
docs/usage/convenience-functions.md
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# Convenience functions
|
||||||
|
|
||||||
|
OOXML and this library mainly uses a unit called twentieths of a point or `twip` for short. a twip is a typographical measurement, defined as 1/20 of a typographical point. One twip is 1/1440 inch, or 17.64 μm. This unit is not intuitive for many users, so some functions were created to help
|
||||||
|
|
||||||
|
More info here: https://en.wikipedia.org/wiki/Twip
|
||||||
|
|
||||||
|
## Convert Inches to Twip
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { convertInchesToTwip } from "docx";
|
||||||
|
|
||||||
|
const twip = convertInchesToTwip(1); // returns 1440
|
||||||
|
const twip = convertInchesToTwip(0.5); // returns 720
|
||||||
|
```
|
||||||
|
|
||||||
|
## Convert Millimeters to Twip
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { convertMillimetersToTwip } from "docx";
|
||||||
|
|
||||||
|
const twip = convertMillimetersToTwip(50); // returns 2834
|
||||||
|
```
|
@ -30,6 +30,24 @@ const doc = new docx.Document({
|
|||||||
* keywords
|
* keywords
|
||||||
* lastModifiedBy
|
* lastModifiedBy
|
||||||
* revision
|
* revision
|
||||||
|
* externalStyles
|
||||||
|
* styles
|
||||||
|
* numbering
|
||||||
|
* footnotes
|
||||||
|
* hyperlinks
|
||||||
|
* background
|
||||||
|
|
||||||
|
### Change background color of Document
|
||||||
|
|
||||||
|
Set the hex value in the document like so:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new docx.Document({
|
||||||
|
background: {
|
||||||
|
color: "C45911",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
You can mix and match whatever properties you want, or provide no properties.
|
You can mix and match whatever properties you want, or provide no properties.
|
||||||
|
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
Every Section has a sections which you can define its Headers and Footers:
|
Every Section has a sections which you can define its Headers and Footers:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
headers: {
|
headers: {
|
||||||
default: new Header({ // The standard default header
|
default: new Header({ // The standard default header
|
||||||
children: [],
|
children: [],
|
||||||
@ -29,11 +30,10 @@ doc.addSection({
|
|||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want more head
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
Example showing basic header and footer
|
Example showing basic header and footer
|
||||||
|
@ -5,7 +5,12 @@
|
|||||||
To create a `floating` image on top of text:
|
To create a `floating` image on top of text:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
const image = new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
}
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
offset: 1014400,
|
offset: 1014400,
|
||||||
@ -20,45 +25,50 @@ Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
|||||||
By default with no arguments, its an `inline` image:
|
By default with no arguments, its an `inline` image:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const image = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"));
|
const image = new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 100,
|
||||||
|
height: 100,
|
||||||
|
},
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Add it into the document by adding the image into a paragraph:
|
Add it into the document by adding the image into a paragraph:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
children: [new Paragraph(image)],
|
sections: [{
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
Or:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
doc.addSection({
|
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [image],
|
children: [image],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Intro
|
## Intro
|
||||||
|
|
||||||
Adding images can be done in two ways:
|
Adding images can be easily done by creating an instance of `ImageRun`. This can be added in a `Paragraph` or `Hyperlink`:
|
||||||
|
|
||||||
1. Call the `createImage` method to add the image directly into the `document`:
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
Media.addImage(doc, [IMAGE_BUFFER], [WIDTH], [HEIGHT], [POSITION_OPTIONS]);
|
const doc = new Document({
|
||||||
```
|
sections: [{
|
||||||
|
children: [
|
||||||
2. Create an `image` first, then add it into the `document`:
|
new Paragraph({
|
||||||
|
children: [
|
||||||
```ts
|
new ImageRun({
|
||||||
const image = Media.addImage(doc, [IMAGE_BUFFER]);
|
data: [IMAGE_BUFFER],
|
||||||
doc.addSection({
|
transformation: {
|
||||||
children: [new Paragraph(image)],
|
width: [IMAGE_SIZE],
|
||||||
|
height: [IMAGE_SIZE],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -75,7 +85,7 @@ Three types of image positioning is supported:
|
|||||||
- Floating
|
- Floating
|
||||||
- Inline
|
- Inline
|
||||||
|
|
||||||
By default, picture are exported as `Inline` elements.
|
By default, images are exported as `Inline` elements.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@ -86,7 +96,12 @@ Pass `options` into the `[POSITION_OPTIONS]` metioned in the [Intro above](#Intr
|
|||||||
To change the position the image to be on top of the text, simply add the `floating` property to the last argument. By default, the offsets are relative to the top left corner of the `page`. Offset units are in [emus](https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/):
|
To change the position the image to be on top of the text, simply add the `floating` property to the last argument. By default, the offsets are relative to the top left corner of the `page`. Offset units are in [emus](https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/):
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const imageData = document.createImage(buffer, 903, 1149, {
|
const image = new ImageRun({
|
||||||
|
data: buffer,
|
||||||
|
transformation: {
|
||||||
|
width: 903,
|
||||||
|
height: 1149,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
offset: 1014400, // relative: HorizontalPositionRelativeFrom.PAGE by default
|
offset: 1014400, // relative: HorizontalPositionRelativeFrom.PAGE by default
|
||||||
@ -99,7 +114,12 @@ const imageData = document.createImage(buffer, 903, 1149, {
|
|||||||
```
|
```
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const imageData = document.createImage(buffer, 903, 1149, {
|
const image = new ImageRun({
|
||||||
|
data: buffer,
|
||||||
|
transformation: {
|
||||||
|
width: 903,
|
||||||
|
height: 1149,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
relative: HorizontalPositionRelativeFrom.RIGHT_MARGIN,
|
relative: HorizontalPositionRelativeFrom.RIGHT_MARGIN,
|
||||||
@ -125,6 +145,7 @@ Full options you can pass into `floating` are:
|
|||||||
| lockAnchor | `boolean` | Optional |
|
| lockAnchor | `boolean` | Optional |
|
||||||
| behindDocument | `boolean` | Optional |
|
| behindDocument | `boolean` | Optional |
|
||||||
| layoutInCell | `boolean` | Optional |
|
| layoutInCell | `boolean` | Optional |
|
||||||
|
| zIndex | `number` | Optional |
|
||||||
|
|
||||||
`HorizontalPositionOptions` are:
|
`HorizontalPositionOptions` are:
|
||||||
|
|
||||||
@ -158,7 +179,12 @@ wrap: {
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
const image = new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
offset: 2014400,
|
offset: 2014400,
|
||||||
@ -201,7 +227,12 @@ margins: {
|
|||||||
For example:
|
For example:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif"), 200, 200, {
|
const image = new ImageRun({
|
||||||
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
||||||
|
transformation: {
|
||||||
|
width: 200,
|
||||||
|
height: 200,
|
||||||
|
},
|
||||||
floating: {
|
floating: {
|
||||||
horizontalPosition: {
|
horizontalPosition: {
|
||||||
offset: 2014400,
|
offset: 2014400,
|
||||||
|
265
docs/usage/math.md
Normal file
265
docs/usage/math.md
Normal file
@ -0,0 +1,265 @@
|
|||||||
|
# Math
|
||||||
|
|
||||||
|
!> Math requires an understanding of [Sections](usage/sections.md) and [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
1. To add math, create a `Math` object
|
||||||
|
2. Add `MathComponents` inside `Math`
|
||||||
|
3. `MathComponents` can have nested `MathComponents` inside. e.g. A fraction where the numerator is a square root, and the demoninator as another fraction. More on `MathComponents` below
|
||||||
|
4. Make sure to add the `Math` object inside a `Paragraph`
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRun("2+2"),
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("hi")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
This will produce:
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img alt="clippy the assistant" src="images/math-example.png" width="200">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## Math Components
|
||||||
|
|
||||||
|
`MathComponents` are the unit sized building blocks of an equation in `docx`. A `MathComponent` takes in more nested `MathComponents` until you reach `MathRun`, which has no children. `MathRun` is similar to a [TextRun](usage/text.md).
|
||||||
|
|
||||||
|
### Math Run
|
||||||
|
|
||||||
|
`MathRun` is the most basic `MathComponent`.
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRun("2+2");
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRun("hello");
|
||||||
|
```
|
||||||
|
|
||||||
|
An example of it being used inside `Math`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathRun("2"),
|
||||||
|
new MathRun("+"),
|
||||||
|
new MathRun("2"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Math Fraction
|
||||||
|
|
||||||
|
`MathFractions` require a `numerator` and a `demoninator`, which are both a list of `MathComponents`
|
||||||
|
|
||||||
|
#### Example
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [
|
||||||
|
new MathRun("1"),
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
An example of it being used inside `Math`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Math({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
new MathText("+"),
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
new MathText("= 1"),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sum
|
||||||
|
|
||||||
|
A `MathComponent` for `Σ`. It can take a `superScript` and/or `subScript` as arguments to add `MathComponents` (usually limits) on the top and bottom
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSum({
|
||||||
|
children: [new MathRun("i")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSum({
|
||||||
|
children: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("e")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
})
|
||||||
|
],
|
||||||
|
subScript: [new MathRun("i")],
|
||||||
|
superScript: [new MathRun("10")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Radicals
|
||||||
|
|
||||||
|
A `MathComponent` for the `√` symbol. Examples include, square root, cube root etc. There is an optional `degree` parameter to specify the number of times the radicand is multiplied by itself. For example, `3` for cube root.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRadical({
|
||||||
|
children: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
Cube root example:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRadical({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
new MathRun('+ 1'),
|
||||||
|
],
|
||||||
|
degree: [new MathRun("3")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Super Script
|
||||||
|
|
||||||
|
`MathSuperScripts` are the little numbers written to the top right of numbers or variables. It means the exponent or power if written by itself with the number or variable.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("x")],
|
||||||
|
superScript: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
An example with cosine:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("cos")],
|
||||||
|
superScript: [new MathRun("-1")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sub Script
|
||||||
|
|
||||||
|
`MathSubScripts` are similar to `MathSuperScripts`, except the little number is written below.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSubScript({
|
||||||
|
children: [new MathRun("F")],
|
||||||
|
subScript: [new MathRun("n-1")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Sub-Super Script
|
||||||
|
|
||||||
|
`MathSubSuperScripts` are a combination of both `MathSuperScript` and `MathSubScript`.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSubSuperScript({
|
||||||
|
children: [new MathRun("test")],
|
||||||
|
superScript: [new MathRun("hello")],
|
||||||
|
subScript: [new MathRun("world")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function
|
||||||
|
|
||||||
|
`MathFunctions` are a way of describing what happens to an input variable, in order to get the output result. It takes a `name` parameter to specify the name of the function.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathFunction({
|
||||||
|
name: [
|
||||||
|
new MathSuperScript({
|
||||||
|
children: [new MathRun("cos")],
|
||||||
|
superScript: [new MathRun("-1")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
children: [new MathRun("100")],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
### Brackets
|
||||||
|
|
||||||
|
#### Square brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathSquareBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Round brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathRoundBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Curly brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathCurlyBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Angled brackets
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new MathAngledBrackets({
|
||||||
|
children: [
|
||||||
|
new MathFraction({
|
||||||
|
numerator: [new MathRun("1")],
|
||||||
|
denominator: [new MathRun("2")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
```
|
@ -2,11 +2,7 @@
|
|||||||
|
|
||||||
> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
|
> Packers are the way in which `docx` turns your code into `.docx` format. It is completely decoupled from the `docx.Document`.
|
||||||
|
|
||||||
Packers in `version 4` and above are now one single `Packer`. It works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of version 4, this library will not have options to export to PDF.
|
Packers works in both a node and browser environment (Angular etc). Now, the packer returns a `Buffer`, `Blob` or `base64 string`. It is up to you to take that and persist it with node's `fs`, send it down as a downloadable file, or anything else you wish. As of `version 4+`, this library will not have options to export to PDF.
|
||||||
|
|
||||||
## Version 5
|
|
||||||
|
|
||||||
Packers in `version 5` and above are now static methods on `Packer`.
|
|
||||||
|
|
||||||
### Export as Buffer
|
### Export as Buffer
|
||||||
|
|
||||||
@ -36,117 +32,3 @@ Packer.toBlob(doc).then((blob) => {
|
|||||||
saveAs(blob, "example.docx");
|
saveAs(blob, "example.docx");
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Version 4
|
|
||||||
|
|
||||||
The `Packer` in `version 4` requires an instance of `Packer`, so be sure to `new` it.
|
|
||||||
|
|
||||||
### Export as Buffer
|
|
||||||
|
|
||||||
This will return a NodeJS `Buffer`. If this is used in the browser, it will return a `UInt8Array` instead.
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const packer = new docx.Packer();
|
|
||||||
|
|
||||||
packer.toBuffer(doc).then((buffer) => {
|
|
||||||
fs.writeFileSync("My Document.docx", buffer);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Export as a `base64` string
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const packer = new docx.Packer();
|
|
||||||
|
|
||||||
packer.toBase64String(doc).then((string) => {
|
|
||||||
console.log(string);
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
### Export as Blob
|
|
||||||
|
|
||||||
This is useful if you want to send it as an downloadable in a browser environment.
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const packer = new docx.Packer();
|
|
||||||
|
|
||||||
packer.toBlob(doc).then((blob) => {
|
|
||||||
// saveAs from FileSaver will download the file
|
|
||||||
saveAs(blob, "example.docx");
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Version 3 and below
|
|
||||||
|
|
||||||
### File System Packer
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const docx = require("docx");
|
|
||||||
|
|
||||||
const doc = new docx.Document();
|
|
||||||
const exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.pack("My Document");
|
|
||||||
// Word Document is in file system
|
|
||||||
```
|
|
||||||
|
|
||||||
### Buffer Packer
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const docx = require("docx");
|
|
||||||
|
|
||||||
const doc = new docx.Document();
|
|
||||||
const exporter = new docx.BufferPacker(doc);
|
|
||||||
const buffer = exporter.pack();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Stream Packer
|
|
||||||
|
|
||||||
Creates a `node` `Readable` stream
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const docx = require("docx");
|
|
||||||
|
|
||||||
const doc = new docx.Document();
|
|
||||||
const exporter = new docx.StreamPacker(doc);
|
|
||||||
const stream = exporter.pack();
|
|
||||||
```
|
|
||||||
|
|
||||||
### Express Packer
|
|
||||||
|
|
||||||
The old express packer is now deprecated and may disappear soon, so you should upgrade.
|
|
||||||
|
|
||||||
The reason for this is because it means this project needs to know about and use `express`, which for a Word document generator, does not sound right. Seperation of concerns.
|
|
||||||
|
|
||||||
It will still be usable (for now), but it is ill advised.
|
|
||||||
|
|
||||||
I used the express exporter in my [website](http://www.dolan.bio).
|
|
||||||
|
|
||||||
The recommended way is to use the `StreamPacker` and handle the `express` magic outside of the library:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const docx = require("docx");
|
|
||||||
|
|
||||||
const doc = new docx.Document();
|
|
||||||
const exporter = new docx.StreamPacker(doc);
|
|
||||||
|
|
||||||
const stream = exporter.pack();
|
|
||||||
|
|
||||||
// Express' response object
|
|
||||||
res.attachment("yourfile.xlsx");
|
|
||||||
stream.pipe(res);
|
|
||||||
```
|
|
||||||
|
|
||||||
where `res` is the response object obtained through the Express router. It is that simple. The file will begin downloading in the browser.
|
|
||||||
|
|
||||||
### PDF Exporting
|
|
||||||
|
|
||||||
You can export your word document as a PDF file like so:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const exporter = new docx.LocalPacker(doc);
|
|
||||||
exporter.packPdf("My Document");
|
|
||||||
|
|
||||||
// Express
|
|
||||||
const exporter = new docx.ExpressPacker(doc, res);
|
|
||||||
exporter.packPdf("My Document");
|
|
||||||
```
|
|
||||||
|
@ -32,23 +32,27 @@ const paragraph = new Paragraph({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
After you create the paragraph, you must add the paragraph into the `document's section`. Learn more about `sections` here:
|
After you create the paragraph, you must add the paragraph into a `section`:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
children: [paragraph],
|
children: [paragraph],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Or the preferred convension, define the paragraph inside the section and remove the usage of variables:
|
Or the preferred convension, define the paragraph inside the section and remove the usage of variables:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
|
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -72,11 +76,13 @@ This is the list of options for a paragraph. A detailed explanation is below:
|
|||||||
| indent | `IIndentAttributesProperties` | Optional | |
|
| indent | `IIndentAttributesProperties` | Optional | |
|
||||||
| keepLines | `boolean` | Optional | |
|
| keepLines | `boolean` | Optional | |
|
||||||
| keepNext | `boolean` | Optional | |
|
| keepNext | `boolean` | Optional | |
|
||||||
| children | `(TextRun or PictureRun or Hyperlink)[]` | Optional | |
|
| children | `(TextRun or ImageRun or Hyperlink)[]` | Optional | |
|
||||||
| style | `string` | Optional | |
|
| style | `string` | Optional | |
|
||||||
| tabStop | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
| [tabStop](usage/tab-stops) | `{ left?: ITabStopOptions; right?: ITabStopOptions; maxRight?: { leader: LeaderType; }; center?: ITabStopOptions }` | Optional | |
|
||||||
| bullet | `{ level: number }` | Optional | |
|
| [bullet](usage/bullet-points) | `{ level: number }` | Optional | |
|
||||||
| numbering | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
| [numbering](usage/numbering) | `{ num: ConcreteNumbering; level: number; custom?: boolean }` | Optional | |
|
||||||
|
| [widowControl](#widow-control) | `boolean` | Optional | |
|
||||||
|
| [frame](usage/text-frames.md) | `IFrameOptions` | Optional | |
|
||||||
|
|
||||||
## Text
|
## Text
|
||||||
|
|
||||||
@ -142,6 +148,32 @@ const paragraph = new Paragraph({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Shading
|
||||||
|
|
||||||
|
Add color to an entire paragraph block
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "shading",
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Widow Control
|
||||||
|
|
||||||
|
Allow First/Last Line to Display on a Separate Page
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const paragraph = new Paragraph({
|
||||||
|
text: "shading",
|
||||||
|
widowControl: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Spacing
|
## Spacing
|
||||||
|
|
||||||
Adding spacing between paragraphs
|
Adding spacing between paragraphs
|
||||||
@ -149,11 +181,11 @@ Adding spacing between paragraphs
|
|||||||
### ISpacingProperties
|
### ISpacingProperties
|
||||||
|
|
||||||
| Property | Type | Notes |
|
| Property | Type | Notes |
|
||||||
| -------- | -------- | -------- |
|
| -------- | -------------- | -------- |
|
||||||
| after | `number` | Optional |
|
| after | `number` | Optional |
|
||||||
| before | `number` | Optional |
|
| before | `number` | Optional |
|
||||||
| line | `number` | Optional |
|
| line | `number` | Optional |
|
||||||
| lineRule | `string` | Optional |
|
| lineRule | `LineRuleType` | Optional |
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
@ -180,7 +212,7 @@ const paragraph = new Paragraph({
|
|||||||
|
|
||||||
## Styles
|
## Styles
|
||||||
|
|
||||||
To create styles, please refer to the styling Wiki: https://github.com/dolanmiu/docx/wiki/Styling
|
To create styles, please refer to the [styling documentation](usage/styling-with-js)
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
@ -11,11 +11,42 @@ For example, you could have one section which is portrait with a header and foot
|
|||||||
This creates a simple section in a document with one paragraph inside:
|
This creates a simple section in a document with one paragraph inside:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
children: [
|
children: [
|
||||||
new Paragraph({
|
new Paragraph({
|
||||||
children: [new TextRun("Hello World")],
|
children: [new TextRun("Hello World")],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
}];
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Properties
|
||||||
|
|
||||||
|
You can specify additional properties to the section, by providing a `properties` attribute.
|
||||||
|
|
||||||
|
### Section Type
|
||||||
|
|
||||||
|
Setting the section type determines how the contents of the section will be placed relative to the previous section. E.g., There are five different types:
|
||||||
|
|
||||||
|
- `CONTINUOUS`
|
||||||
|
- `EVEN_PAGE`
|
||||||
|
- `NEXT_COLUMN`
|
||||||
|
- `NEXT_PAGE`
|
||||||
|
- `ODD_PAGE`
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
|
properties: {
|
||||||
|
type: SectionType.CONTINUOUS,
|
||||||
|
}
|
||||||
|
children: [
|
||||||
|
new Paragraph({
|
||||||
|
children: [new TextRun("Hello World")],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
|
|
||||||
## Intro
|
## Intro
|
||||||
|
|
||||||
* `Tables` contain a list of `Rows`
|
- `Tables` contain a list of `Rows`
|
||||||
* `Rows` contain a list of `TableCells`
|
- `Rows` contain a list of `TableCells`
|
||||||
* `TableCells` contain a list of `Parahraphs` and/or `Tables`. You can add `Tables` as tables can be nested inside each other
|
- `TableCells` contain a list of `Parahraphs` and/or `Tables`. You can add `Tables` as tables can be nested inside each other
|
||||||
|
|
||||||
Create a simple table like so:
|
Create a simple table like so:
|
||||||
|
|
||||||
@ -19,8 +19,10 @@ const table = new Table({
|
|||||||
Then add the table in the `section`
|
Then add the table in the `section`
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
doc.addSection({
|
const doc = new Document({
|
||||||
|
sections: [{
|
||||||
children: [table],
|
children: [table],
|
||||||
|
}];
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -51,19 +53,6 @@ const table = new Table({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Pagination
|
|
||||||
|
|
||||||
#### Prevent row pagination
|
|
||||||
|
|
||||||
To prevent breaking contents of a row across multiple pages, call `cantSplit`:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const table = new Table({
|
|
||||||
rows: [],
|
|
||||||
cantSplit: true,
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
## Table Row
|
## Table Row
|
||||||
|
|
||||||
A table consists of multiple `table rows`. Table rows have a list of `children` which accepts a list of `table cells` explained below. You can create a simple `table row` like so:
|
A table consists of multiple `table rows`. Table rows have a list of `children` which accepts a list of `table cells` explained below. You can create a simple `table row` like so:
|
||||||
@ -99,11 +88,11 @@ const table = new Table({
|
|||||||
Here is a list of options you can add to the `table row`:
|
Here is a list of options you can add to the `table row`:
|
||||||
|
|
||||||
| Property | Type | Notes |
|
| Property | Type | Notes |
|
||||||
| ----------- | ------------------------------------- | -------- |
|
| ----------- | -------------------------------------- | -------- |
|
||||||
| children | `Array<TableCell>` | Required |
|
| children | `Array<TableCell>` | Required |
|
||||||
| cantSplit | `boolean` | Optional |
|
| cantSplit | `boolean` | Optional |
|
||||||
| tableHeader | `boolean` | Optional |
|
| tableHeader | `boolean` | Optional |
|
||||||
| height | `{ value: number, rule: HeightRule }` | Optional |
|
| height | `{ height: number, rule: HeightRule }` | Optional |
|
||||||
|
|
||||||
### Repeat row
|
### Repeat row
|
||||||
|
|
||||||
@ -116,6 +105,19 @@ const row = new TableRow({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Pagination
|
||||||
|
|
||||||
|
#### Prevent row pagination
|
||||||
|
|
||||||
|
To prevent breaking contents of a row across multiple pages, call `cantSplit`:
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const row = new Row({
|
||||||
|
...,
|
||||||
|
cantSplit: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Table Cells
|
## Table Cells
|
||||||
|
|
||||||
Cells need to be added in the `table row`, you can create a table cell like:
|
Cells need to be added in the `table row`, you can create a table cell like:
|
||||||
@ -142,7 +144,7 @@ const tableRow = new TableRow({
|
|||||||
|
|
||||||
| Property | Type | Notes |
|
| Property | Type | Notes |
|
||||||
| ------------- | ----------------------------------- | ----------------------------------------------------------- |
|
| ------------- | ----------------------------------- | ----------------------------------------------------------- |
|
||||||
| children | `Array<Paragraph | Table>` | Required. You can nest tables by adding a table into a cell |
|
| children | `Array<Paragraph or Table>` | Required. You can nest tables by adding a table into a cell |
|
||||||
| shading | `ITableShadingAttributesProperties` | Optional |
|
| shading | `ITableShadingAttributesProperties` | Optional |
|
||||||
| margins | `ITableCellMarginOptions` | Optional |
|
| margins | `ITableCellMarginOptions` | Optional |
|
||||||
| verticalAlign | `VerticalAlign` | Optional |
|
| verticalAlign | `VerticalAlign` | Optional |
|
||||||
@ -326,6 +328,16 @@ const cell = new TableCell({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Visual Right to Left Table
|
||||||
|
|
||||||
|
It is possible to reverse how the cells of the table are displayed. The table direction. More info here: https://superuser.com/questions/996912/how-to-change-a-table-direction-in-microsoft-word
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const table = new Table({
|
||||||
|
visuallyRightToLeft: true,
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/4-basic-table.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/4-basic-table.ts ':include')
|
||||||
|
69
docs/usage/text-frames.md
Normal file
69
docs/usage/text-frames.md
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
# Text Frames
|
||||||
|
|
||||||
|
Also known as `Text Boxes`
|
||||||
|
|
||||||
|
!> Text Frames requires an understanding of [Paragraphs](usage/paragraph.md).
|
||||||
|
|
||||||
|
> Text frames are paragraphs of text in a document which are positioned in a separate region or frame in the document, and can be positioned with a specific size and position relative to non-frame paragraphs in the current document.
|
||||||
|
|
||||||
|
## Intro
|
||||||
|
|
||||||
|
To make a `Text Frame`, simply add the `frame` property on a paragraph. `Borders` can be applied to frame simply by adding the `border` attribute.
|
||||||
|
|
||||||
|
```ts
|
||||||
|
new Paragraph({
|
||||||
|
frame: {
|
||||||
|
position: {
|
||||||
|
x: 1000,
|
||||||
|
y: 3000,
|
||||||
|
},
|
||||||
|
width: 4000,
|
||||||
|
height: 1000,
|
||||||
|
anchor: {
|
||||||
|
horizontal: FrameAnchorType.MARGIN,
|
||||||
|
vertical: FrameAnchorType.MARGIN,
|
||||||
|
},
|
||||||
|
alignment: {
|
||||||
|
x: HorizontalPositionAlign.CENTER,
|
||||||
|
y: VerticalPositionAlign.TOP,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
border: {
|
||||||
|
top: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
bottom: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
left: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
right: {
|
||||||
|
color: "auto",
|
||||||
|
space: 1,
|
||||||
|
value: "single",
|
||||||
|
size: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
children: [
|
||||||
|
new TextRun("Hello World"),
|
||||||
|
new TextRun({
|
||||||
|
text: "Foo Bar",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
new TextRun({
|
||||||
|
text: "\tGithub is the best",
|
||||||
|
bold: true,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
});
|
||||||
|
```
|
@ -77,40 +77,78 @@ const text = new TextRun({
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Shading and Highlighting
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "shading",
|
||||||
|
shading: {
|
||||||
|
type: ShadingType.REVERSE_DIAGONAL_STRIPE,
|
||||||
|
color: "00FFFF",
|
||||||
|
fill: "FF0000",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
```ts
|
||||||
|
const text = new TextRun({
|
||||||
|
text: "highlighting",
|
||||||
|
highlight: "yellow",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
### Strike through
|
### Strike through
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.strike();
|
const text = new TextRun({
|
||||||
|
text: "strike",
|
||||||
|
strike: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Double strike through
|
### Double strike through
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.doubleStrike();
|
const text = new TextRun({
|
||||||
|
text: "doubleStrike",
|
||||||
|
doubleStrike: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Superscript
|
### Superscript
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.superScript();
|
const text = new TextRun({
|
||||||
|
text: "superScript",
|
||||||
|
superScript: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Subscript
|
### Subscript
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.subScript();
|
const text = new TextRun({
|
||||||
|
text: "subScript",
|
||||||
|
subScript: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### All Capitals
|
### All Capitals
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.allCaps();
|
const text = new TextRun({
|
||||||
|
text: "allCaps",
|
||||||
|
allCaps: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Small Capitals
|
### Small Capitals
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.smallCaps();
|
const text = new TextRun({
|
||||||
|
text: "smallCaps",
|
||||||
|
smallCaps: true,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Break
|
## Break
|
||||||
@ -118,13 +156,17 @@ text.smallCaps();
|
|||||||
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
Sometimes you would want to put text underneath another line of text but inside the same paragraph.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
text.break();
|
const text = new TextRun({
|
||||||
|
text: "break",
|
||||||
|
break: 1,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
## Chaining
|
Adding two breaks:
|
||||||
|
|
||||||
What if you want to create a paragraph which is **_bold_** and **_italic_**?
|
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
paragraph.bold().italics();
|
const text = new TextRun({
|
||||||
|
text: "break",
|
||||||
|
break: 2,
|
||||||
|
});
|
||||||
```
|
```
|
||||||
|
3738
package-lock.json
generated
3738
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "docx",
|
"name": "docx",
|
||||||
"version": "5.2.2",
|
"version": "6.0.0",
|
||||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||||
"main": "build/index.js",
|
"main": "build/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@ -14,7 +14,7 @@
|
|||||||
"tsc": "rimraf ./build && tsc -p .",
|
"tsc": "rimraf ./build && tsc -p .",
|
||||||
"webpack": "rimraf ./build && webpack",
|
"webpack": "rimraf ./build && webpack",
|
||||||
"demo": "npm run build && npm run ts-node ./demo",
|
"demo": "npm run build && npm run ts-node ./demo",
|
||||||
"typedoc": "typedoc src/index.ts",
|
"typedoc": "rimraf ./build && typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
||||||
"style": "prettier -l \"src/**/*.ts\"",
|
"style": "prettier -l \"src/**/*.ts\"",
|
||||||
"style.fix": "npm run style -- --write",
|
"style.fix": "npm run style -- --write",
|
||||||
"fix-types": "ts-node scripts/types-absolute-fixer.ts",
|
"fix-types": "ts-node scripts/types-absolute-fixer.ts",
|
||||||
@ -52,7 +52,7 @@
|
|||||||
"@types/jszip": "^3.1.4",
|
"@types/jszip": "^3.1.4",
|
||||||
"@types/node": "^14.0.5",
|
"@types/node": "^14.0.5",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"shortid": "^2.2.15",
|
"nanoid": "^3.1.20",
|
||||||
"xml": "^1.0.1",
|
"xml": "^1.0.1",
|
||||||
"xml-js": "^1.6.8"
|
"xml-js": "^1.6.8"
|
||||||
},
|
},
|
||||||
@ -63,11 +63,10 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/dolanmiu/docx#readme",
|
"homepage": "https://github.com/dolanmiu/docx#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chai": "^3.4.35",
|
"@types/chai": "^4.2.15",
|
||||||
"@types/mocha": "^2.2.39",
|
"@types/mocha": "^8.0.0",
|
||||||
"@types/request-promise": "^4.1.42",
|
"@types/request-promise": "^4.1.42",
|
||||||
"@types/shortid": "0.0.29",
|
"@types/sinon": "^9.0.4",
|
||||||
"@types/sinon": "^4.3.1",
|
|
||||||
"@types/webpack": "^4.4.24",
|
"@types/webpack": "^4.4.24",
|
||||||
"awesome-typescript-loader": "^3.4.1",
|
"awesome-typescript-loader": "^3.4.1",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
@ -77,24 +76,24 @@
|
|||||||
"jszip": "^3.1.5",
|
"jszip": "^3.1.5",
|
||||||
"mocha": "^5.2.0",
|
"mocha": "^5.2.0",
|
||||||
"mocha-webpack": "^1.0.1",
|
"mocha-webpack": "^1.0.1",
|
||||||
"nyc": "^14.1.1",
|
"nyc": "^15.1.0",
|
||||||
"pre-commit": "^1.2.2",
|
"pre-commit": "^1.2.2",
|
||||||
"prettier": "^1.15.2",
|
"prettier": "^2.1.2",
|
||||||
"prompt": "^1.0.0",
|
"prompt": "^1.0.0",
|
||||||
"replace-in-file": "^3.1.0",
|
"replace-in-file": "^3.1.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"request-promise": "^4.2.2",
|
"request-promise": "^4.2.2",
|
||||||
"rimraf": "^2.5.2",
|
"rimraf": "^3.0.2",
|
||||||
"shelljs": "^0.7.7",
|
"shelljs": "^0.8.4",
|
||||||
"sinon": "^5.0.7",
|
"sinon": "^9.0.2",
|
||||||
"ts-node": "^7.0.1",
|
"ts-node": "^9.0.0",
|
||||||
"tslint": "^5.11.0",
|
"tslint": "^6.1.3",
|
||||||
"tslint-immutable": "^4.9.0",
|
"tslint-immutable": "^6.0.1",
|
||||||
"typedoc": "^0.11.1",
|
"typedoc": "^0.20.29",
|
||||||
"typescript": "2.9.2",
|
"typescript": "4.2.3",
|
||||||
"webpack": "^3.10.0"
|
"webpack": "^3.10.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
33
src/convenience-functions.spec.ts
Normal file
33
src/convenience-functions.spec.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { convertInchesToTwip, convertMillimetersToTwip, uniqueId, uniqueNumericId } from "./convenience-functions";
|
||||||
|
|
||||||
|
describe("Utility", () => {
|
||||||
|
describe("#convertMillimetersToTwip", () => {
|
||||||
|
it("should call the underlying header's addChildElement for Paragraph", () => {
|
||||||
|
expect(convertMillimetersToTwip(1000)).to.equal(56692);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#convertInchesToTwip", () => {
|
||||||
|
it("should call the underlying header's addChildElement", () => {
|
||||||
|
expect(convertInchesToTwip(1)).to.equal(1440);
|
||||||
|
expect(convertInchesToTwip(0.5)).to.equal(720);
|
||||||
|
expect(convertInchesToTwip(0.25)).to.equal(360);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#uniqueNumericId", () => {
|
||||||
|
it("should generate a unique ID", () => {
|
||||||
|
// tslint:disable-next-line: no-unused-expression
|
||||||
|
expect(uniqueNumericId()).to.not.be.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#uniqueId", () => {
|
||||||
|
it("should call the underlying header's addChildElement", () => {
|
||||||
|
// tslint:disable-next-line: no-unused-expression
|
||||||
|
expect(uniqueId()).to.not.be.empty;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
20
src/convenience-functions.ts
Normal file
20
src/convenience-functions.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { customAlphabet, nanoid } from "nanoid/non-secure";
|
||||||
|
|
||||||
|
const numericNanoId = customAlphabet("0123456789", 15);
|
||||||
|
|
||||||
|
// Twip - twentieths of a point
|
||||||
|
export const convertMillimetersToTwip = (millimeters: number): number => {
|
||||||
|
return Math.floor((millimeters / 25.4) * 72 * 20);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const convertInchesToTwip = (inches: number): number => {
|
||||||
|
return Math.floor(inches * 72 * 20);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const uniqueNumericId = (): number => {
|
||||||
|
return parseFloat(numericNanoId());
|
||||||
|
};
|
||||||
|
|
||||||
|
export const uniqueId = (): string => {
|
||||||
|
return nanoid().toLowerCase();
|
||||||
|
};
|
@ -1,9 +1,9 @@
|
|||||||
import { BaseXmlComponent, IXmlableObject } from "file/xml-components";
|
import { BaseXmlComponent, IContext, IXmlableObject } from "file/xml-components";
|
||||||
import { File } from "../file";
|
|
||||||
|
|
||||||
export class Formatter {
|
export class Formatter {
|
||||||
public format(input: BaseXmlComponent, file?: File): IXmlableObject {
|
// tslint:disable-next-line: no-object-literal-type-assertion
|
||||||
const output = input.prepForXml(file);
|
public format(input: BaseXmlComponent, context: IContext = {} as IContext): IXmlableObject {
|
||||||
|
const output = input.prepForXml(context);
|
||||||
|
|
||||||
if (output) {
|
if (output) {
|
||||||
return output;
|
return output;
|
||||||
|
61
src/export/packer/image-replacer.spec.ts
Normal file
61
src/export/packer/image-replacer.spec.ts
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
import { expect } from "chai";
|
||||||
|
|
||||||
|
import { Media } from "file";
|
||||||
|
|
||||||
|
import { ImageReplacer } from "./image-replacer";
|
||||||
|
|
||||||
|
describe("ImageReplacer", () => {
|
||||||
|
describe("#replace()", () => {
|
||||||
|
it("should replace properly", () => {
|
||||||
|
const imageReplacer = new ImageReplacer();
|
||||||
|
const result = imageReplacer.replace(
|
||||||
|
"test {test-image.png} test",
|
||||||
|
[
|
||||||
|
{
|
||||||
|
stream: Buffer.from(""),
|
||||||
|
fileName: "test-image.png",
|
||||||
|
transformation: {
|
||||||
|
pixels: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
emus: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
0,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).to.equal("test 0 test");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("#getMediaData()", () => {
|
||||||
|
it("should get media data", () => {
|
||||||
|
const imageReplacer = new ImageReplacer();
|
||||||
|
const result = imageReplacer.getMediaData("test {test-image} test", ({
|
||||||
|
Array: [
|
||||||
|
{
|
||||||
|
stream: Buffer.from(""),
|
||||||
|
fileName: "test-image",
|
||||||
|
dimensions: {
|
||||||
|
pixels: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
emus: {
|
||||||
|
x: 100,
|
||||||
|
y: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
} as unknown) as Media);
|
||||||
|
|
||||||
|
expect(result).to.have.length(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user