-
-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #482 from dolanmiu/feat/right-indent
Add new image for README
- Loading branch information
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Simple example to add text to a document | ||
// Import from 'docx' rather than '../build' if you install from npm | ||
import * as fs from "fs"; | ||
import { Document, HeadingLevel, Media, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign } from "../build"; | ||
|
||
const doc = new Document(); | ||
|
||
const image1 = Media.addImage(doc, fs.readFileSync("./demo/images/image1.jpeg")); | ||
const image2 = Media.addImage(doc, fs.readFileSync("./demo/images/pizza.gif")); | ||
|
||
const table = new Table({ | ||
rows: [ | ||
new TableRow({ | ||
children: [ | ||
new TableCell({ | ||
children: [new Paragraph(image1)], | ||
verticalAlign: VerticalAlign.CENTER, | ||
}), | ||
new TableCell({ | ||
children: [ | ||
new Paragraph({ | ||
text: "Hello", | ||
heading: HeadingLevel.HEADING_1, | ||
}), | ||
], | ||
verticalAlign: VerticalAlign.CENTER, | ||
}), | ||
], | ||
}), | ||
new TableRow({ | ||
children: [ | ||
new TableCell({ | ||
children: [ | ||
new Paragraph({ | ||
text: "World", | ||
heading: HeadingLevel.HEADING_1, | ||
}), | ||
], | ||
}), | ||
new TableCell({ | ||
children: [new Paragraph(image1)], | ||
}), | ||
], | ||
}), | ||
], | ||
}); | ||
|
||
doc.addSection({ | ||
children: [ | ||
new Paragraph({ | ||
text: "Hello World", | ||
heading: HeadingLevel.HEADING_1, | ||
}), | ||
table, | ||
new Paragraph(image2), | ||
], | ||
}); | ||
|
||
Packer.toBuffer(doc).then((buffer) => { | ||
fs.writeFileSync("My Document.docx", buffer); | ||
}); |