Files
docx-js/docs/examples.md
2018-08-06 03:53:27 +01:00

6.4 KiB

Examples

All examples can run independently and can be found in the /demo folder of the project

Simple

A simple hello world of the docx library:

Example

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

Example

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

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo13.js

Numbering

This example shows many levels of numbering

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo3.js

Table

Example of simple table

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo4.js

Styling table borders

Styling the borders of a table

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo20.js

Images

Add image to the document

Importing Images from file system path

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo5.js

Example showing how to add image to headers and footers

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo9.js

Scaling images

Example showing how to scale images

Example

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

Example

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

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo24.js

Images using Base64 URI

If you want to use a Base64 image instead

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.js

Margins

Example showing how to set custom margains

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo6.js

Orientation

Example showing how to set the document to landscape or portrait

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo7.js

Headers & Footers

Example showing how to add headers and footers

Example

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

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo14.js

Page break before

Example showing how to page break before like in Word

Example

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

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo16.js

Footnotes

Example of how to add footnotes. Good for references

Example

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

Example

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

Example

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

Example

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

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo22.js

Showcase

My CV

Example showing how to add headers and footers

Example

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

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/demo11.js