Files
docx-js/demo/35-hyperlinks.ts
Dolan Miu 7bcdaab2f2 Updated Hyperlink demo
To test image followed up by hyperlink bug
2020-02-27 10:44:07 +00:00

37 lines
1010 B
TypeScript

// 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, Media } from "../build";
const doc = new Document({
hyperlinks: {
myCoolLink: {
link: "http://www.example.com",
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")],
}),
],
});
Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("My Document.docx", buffer);
});