Merge branch 'master' into feat/base64-image
This commit is contained in:
20
demo/demo19.js
Normal file
20
demo/demo19.js
Normal file
@ -0,0 +1,20 @@
|
||||
const fs = require("fs");
|
||||
const docx = require("../build");
|
||||
|
||||
var doc = new docx.Document();
|
||||
|
||||
var paragraph = new docx.Paragraph("Hello World");
|
||||
var institutionText = new docx.TextRun("Foo").bold();
|
||||
var dateText = new docx.TextRun("Bar").tab().bold();
|
||||
paragraph.addRun(institutionText);
|
||||
paragraph.addRun(dateText);
|
||||
|
||||
doc.addParagraph(paragraph);
|
||||
|
||||
var exporter = new docx.BufferPacker(doc);
|
||||
exporter.pack("My Document").then((buffer) => {
|
||||
// At this point, you can do anything with the buffer, including casting it to a string etc.
|
||||
console.log(buffer);
|
||||
fs.writeFileSync('My Document.docx', buffer);
|
||||
console.log("Document created successfully at project root!");
|
||||
});
|
17
demo/demo20.js
Normal file
17
demo/demo20.js
Normal file
@ -0,0 +1,17 @@
|
||||
const docx = require("../build");
|
||||
|
||||
var doc = new docx.Document();
|
||||
|
||||
const table = doc.createTable(4, 4);
|
||||
table
|
||||
.getCell(2, 2)
|
||||
.addContent(new docx.Paragraph("Hello"))
|
||||
.cellProperties.borders.addTopBorder(docx.BorderStyle.DASH_DOT_STROKED, 3, "red")
|
||||
.addBottomBorder(docx.BorderStyle.DOUBLE, 3, "blue")
|
||||
.addStartBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "green")
|
||||
.addEndBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "#ff8000");
|
||||
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
exporter.pack("My Document");
|
||||
|
||||
console.log("Document created successfully at project root!");
|
31
demo/demo21.js
Normal file
31
demo/demo21.js
Normal file
@ -0,0 +1,31 @@
|
||||
/** This demo shows how to create bookmarks then link to them with internal hyperlinks */
|
||||
|
||||
const docx = require("../build");
|
||||
|
||||
const loremIpsum = "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.";
|
||||
|
||||
const doc = new docx.Document({
|
||||
creator: 'Clippy',
|
||||
title: 'Sample Document',
|
||||
description: 'A brief example of using docx with bookmarks and internal hyperlinks',
|
||||
});
|
||||
|
||||
const anchorId = "anchorID";
|
||||
|
||||
// First create the bookmark
|
||||
const bookmark = doc.createBookmark(anchorId, "Lorem Ipsum");
|
||||
// That has header styling
|
||||
doc.createParagraph().addBookmark(bookmark).heading1();
|
||||
doc.createParagraph("\n");
|
||||
|
||||
doc.createParagraph(loremIpsum);
|
||||
doc.createParagraph().pageBreak();
|
||||
|
||||
// Now the link back up to the bookmark
|
||||
const hyperlink = doc.createInternalHyperLink(anchorId, `Click me!`);
|
||||
doc.createParagraph().addHyperLink(hyperlink);
|
||||
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
exporter.pack("My Document");
|
||||
|
||||
console.log("Document created successfully at project root!");
|
14
demo/demo22.js
Normal file
14
demo/demo22.js
Normal file
@ -0,0 +1,14 @@
|
||||
const docx = require('../build');
|
||||
|
||||
var doc = new docx.Document();
|
||||
|
||||
var textRun = new docx.TextRun("שלום עולם").rtl();
|
||||
var paragraph = new docx.Paragraph().bidi();
|
||||
paragraph.addRun(textRun);
|
||||
|
||||
doc.addParagraph(paragraph);
|
||||
|
||||
var exporter = new docx.LocalPacker(doc);
|
||||
exporter.pack('My Document');
|
||||
|
||||
console.log('Document created successfully at project root!');
|
Reference in New Issue
Block a user