Files
docx-js/demo/35-hyperlinks.ts

27 lines
667 B
TypeScript
Raw Normal View History

2019-02-26 22:20:20 +00:00
// Example on how to add hyperlinks to websites
2018-12-24 16:50:53 +00:00
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
2019-12-21 03:31:09 +00:00
import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph } from "../build";
2019-01-03 20:47:00 +00:00
2019-12-18 21:11:15 +00:00
const doc = new Document({
hyperlinks: {
myCoolLink: {
link: "http://www.example.com",
text: "Hyperlink",
2019-12-21 03:31:09 +00:00
type: HyperlinkType.EXTERNAL,
2019-12-18 21:11:15 +00:00
},
},
});
2018-12-24 16:50:53 +00:00
2019-07-31 08:48:02 +01:00
doc.addSection({
children: [
new Paragraph({
2019-12-18 21:11:15 +00:00
children: [new HyperlinkRef("myCoolLink")],
}),
],
2019-07-31 08:48:02 +01:00
});
2018-12-24 16:50:53 +00:00
2019-08-07 22:12:14 +01:00
Packer.toBuffer(doc).then((buffer) => {
2018-12-24 16:50:53 +00:00
fs.writeFileSync("My Document.docx", buffer);
});