Make adding images declarative and simple

This commit is contained in:
Dolan
2021-03-18 02:48:37 +00:00
parent c8db70b3b7
commit caf188caae
25 changed files with 1585 additions and 550 deletions

View File

@ -7,7 +7,7 @@ import {
Document,
Footer,
HeadingLevel,
Media,
ImageRun,
Packer,
Paragraph,
Table,
@ -126,15 +126,6 @@ const doc = new Document({
},
});
const image = Media.addImage({
document: doc,
data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: {
width: 100,
height: 100,
},
});
const table = new Table({
rows: [
new TableRow({
@ -168,23 +159,6 @@ const table = new Table({
],
});
const image1 = Media.addImage({
document: doc,
data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: {
width: 100,
height: 100,
},
});
const image2 = Media.addImage({
document: doc,
data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: {
width: 100,
height: 100,
},
});
doc.addSection({
properties: {
top: 700,
@ -204,7 +178,15 @@ doc.addSection({
}),
},
children: [
new Paragraph(image),
new Paragraph(
new ImageRun({
data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: {
width: 100,
height: 100,
},
}),
),
new Paragraph({
text: "HEADING",
heading: HeadingLevel.HEADING_1,
@ -243,12 +225,28 @@ doc.addSection({
style: "normalPara",
}),
table,
new Paragraph(image1),
new Paragraph(
new ImageRun({
data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: {
width: 100,
height: 100,
},
}),
),
new Paragraph({
text: "Test",
style: "normalPara2",
}),
new Paragraph(image2),
new Paragraph(
new ImageRun({
data: fs.readFileSync("./demo/images/pizza.gif"),
transformation: {
width: 100,
height: 100,
},
}),
),
new Paragraph({
text: "Test 2",
style: "normalPara2",