Updated Hyperlink demo

To test image followed up by hyperlink bug
This commit is contained in:
Dolan Miu
2020-02-27 10:44:07 +00:00
parent 5b58e520f9
commit 7bcdaab2f2

View File

@ -1,7 +1,7 @@
// Example on how to add hyperlinks to websites
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph } from "../build";
import { Document, HyperlinkRef, HyperlinkType, Packer, Paragraph, Media } from "../build";
const doc = new Document({
hyperlinks: {
@ -10,14 +10,24 @@ const doc = new Document({
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: [
new Paragraph({
children: [new HyperlinkRef("myCoolLink")],
}),
new Paragraph({
children: [image1, new HyperlinkRef("myOtherLink")],
}),
],
});