6.6 KiB
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:
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:
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo1.js
Styles
Styling with JS
This example shows how to customise the look and feel of a document using JS configuration
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo2.js
Styling with XML
This example shows how to customise the look and feel of a document using XML configuration
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.js
Numbering
This example shows many levels of numbering
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.js
Table
Example of simple table
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.js
Styling table borders
Styling the borders of a table
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.js
Images
Add image to the document
Importing Images from file system path
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.js
Add images to header and footer
Example showing how to add image to headers and footers
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.js
Scaling images
Example showing how to scale images
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo12.js
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
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo23.js
Add image to table
As before, to add an image to a table, you would need to add it to the Media
object first
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.js
Images using Base64 URI
If you want to use a Base64 image instead
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.js
Margins
Example showing how to set custom margains
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.js
Orientation
Example showing how to set the document to landscape
or portrait
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.js
Headers & Footers
Example showing how to add headers and footers
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo8.js
Multiple headers and footers
Check out Sections
for this feature
Page Breaks
Normal page breaks
Example showing how to page break
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.js
Page break before
Example showing how to page break before like in Word
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo15.js
Sections
Example of how sections work. Sections allow multiple headers and footers, and landscape
/portrait
inside the same document
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.js
Footnotes
Example of how to add footnotes. Good for references
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo17.js
Packers
Buffer Packer
Example showing how to use the Buffer packer and then write that buffer to the file system
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo19.js
PDF Packing
Example of how to use the LocalPacker
to create a PDF document
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo25.js
Bookmarks
Example showing how to make bookmarks to make internal hyperlinks within the document
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo21.js
Bidirectional text
Example showing how to use bidirectional text for certain languages such as Hebrew
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.js
Showcase
My CV
Example showing how to add headers and footers
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo10.js
Style and Images
This example shows how to customise the look and feel of a document and add images
Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.js