Make adding images declarative and simple
This commit is contained in:
@ -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, ExternalHyperlink, Footer, FootnoteReferenceRun, Media, Packer, Paragraph, TextRun } from "../build";
|
||||
import { Document, ExternalHyperlink, Footer, FootnoteReferenceRun, ImageRun, Packer, Paragraph, TextRun } from "../build";
|
||||
|
||||
const doc = new Document({
|
||||
footnotes: {
|
||||
@ -24,15 +24,6 @@ const doc = new Document({
|
||||
},
|
||||
});
|
||||
|
||||
const image1 = Media.addImage({
|
||||
document: doc,
|
||||
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
});
|
||||
|
||||
doc.addSection({
|
||||
footers: {
|
||||
default: new Footer({
|
||||
@ -86,7 +77,13 @@ doc.addSection({
|
||||
new Paragraph({
|
||||
children: [
|
||||
new ExternalHyperlink({
|
||||
child: image1,
|
||||
child: new ImageRun({
|
||||
data: fs.readFileSync("./demo/images/image1.jpeg"),
|
||||
transformation: {
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
}),
|
||||
link: "http://www.google.com",
|
||||
}),
|
||||
new ExternalHyperlink({
|
||||
|
Reference in New Issue
Block a user