From 7bcdaab2f280d701edd4e75fc9f80dd658ace840 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 27 Feb 2020 10:44:07 +0000 Subject: [PATCH] Updated Hyperlink demo To test image followed up by hyperlink bug --- demo/35-hyperlinks.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/demo/35-hyperlinks.ts b/demo/35-hyperlinks.ts index fb84f13099..65ed9390d4 100644 --- a/demo/35-hyperlinks.ts +++ b/demo/35-hyperlinks.ts @@ -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")], + }), ], });