2018-08-21 02:46:21 +01:00
|
|
|
// Setting styles with JavaScript configuration
|
|
|
|
// Import from 'docx' rather than '../build' if you install from npm
|
|
|
|
import * as fs from "fs";
|
2019-10-10 01:08:01 +01:00
|
|
|
import {
|
|
|
|
AlignmentType,
|
2020-12-24 03:37:43 +00:00
|
|
|
convertInchesToTwip,
|
2019-10-10 01:08:01 +01:00
|
|
|
Document,
|
|
|
|
Footer,
|
|
|
|
HeadingLevel,
|
2021-03-18 02:48:37 +00:00
|
|
|
ImageRun,
|
2019-10-10 01:08:01 +01:00
|
|
|
Packer,
|
|
|
|
Paragraph,
|
|
|
|
Table,
|
|
|
|
TableCell,
|
|
|
|
TableRow,
|
|
|
|
TabStopPosition,
|
|
|
|
UnderlineType,
|
|
|
|
} from "../build";
|
2018-03-10 23:04:45 +00:00
|
|
|
|
2021-03-19 20:53:56 +00:00
|
|
|
const table = new Table({
|
|
|
|
rows: [
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("Test cell 1.")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("Test cell 2.")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("Test cell 3.")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new TableRow({
|
|
|
|
children: [
|
|
|
|
new TableCell({
|
|
|
|
children: [new Paragraph("Test cell 4.")],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
2019-10-10 01:08:01 +01:00
|
|
|
const doc = new Document({
|
2020-11-30 10:25:58 -06:00
|
|
|
styles: {
|
|
|
|
default: {
|
|
|
|
heading1: {
|
|
|
|
run: {
|
|
|
|
font: "Calibri",
|
|
|
|
size: 52,
|
|
|
|
bold: true,
|
2019-10-10 01:08:01 +01:00
|
|
|
color: "000000",
|
2020-11-30 10:25:58 -06:00
|
|
|
underline: {
|
|
|
|
type: UnderlineType.SINGLE,
|
|
|
|
color: "000000",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
alignment: AlignmentType.CENTER,
|
|
|
|
spacing: { line: 340 },
|
2019-10-10 01:08:01 +01:00
|
|
|
},
|
|
|
|
},
|
2020-11-30 10:25:58 -06:00
|
|
|
heading2: {
|
|
|
|
run: {
|
|
|
|
font: "Calibri",
|
|
|
|
size: 26,
|
|
|
|
bold: true,
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
spacing: { line: 340 },
|
|
|
|
},
|
2020-11-24 13:30:26 -06:00
|
|
|
},
|
2020-11-30 10:25:58 -06:00
|
|
|
heading3: {
|
|
|
|
run: {
|
|
|
|
font: "Calibri",
|
|
|
|
size: 26,
|
|
|
|
bold: true,
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
spacing: { line: 276 },
|
|
|
|
},
|
2020-11-24 13:30:26 -06:00
|
|
|
},
|
2020-11-30 10:25:58 -06:00
|
|
|
heading4: {
|
|
|
|
run: {
|
|
|
|
font: "Calibri",
|
|
|
|
size: 26,
|
|
|
|
bold: true,
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
alignment: AlignmentType.JUSTIFIED,
|
|
|
|
},
|
2019-10-10 01:08:01 +01:00
|
|
|
},
|
2020-11-24 13:30:26 -06:00
|
|
|
},
|
|
|
|
paragraphStyles: [
|
2019-10-10 01:08:01 +01:00
|
|
|
{
|
|
|
|
id: "normalPara",
|
|
|
|
name: "Normal Para",
|
|
|
|
basedOn: "Normal",
|
|
|
|
next: "Normal",
|
|
|
|
quickFormat: true,
|
|
|
|
run: {
|
|
|
|
font: "Calibri",
|
|
|
|
size: 26,
|
|
|
|
bold: true,
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
|
|
|
rightTabStop: TabStopPosition.MAX,
|
|
|
|
leftTabStop: 453.543307087,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "normalPara2",
|
|
|
|
name: "Normal Para2",
|
|
|
|
basedOn: "Normal",
|
|
|
|
next: "Normal",
|
|
|
|
quickFormat: true,
|
|
|
|
run: {
|
|
|
|
font: "Calibri",
|
|
|
|
size: 26,
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
alignment: AlignmentType.JUSTIFIED,
|
|
|
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "aside",
|
|
|
|
name: "Aside",
|
|
|
|
basedOn: "Normal",
|
|
|
|
next: "Normal",
|
|
|
|
run: {
|
|
|
|
color: "999999",
|
|
|
|
italics: true,
|
|
|
|
},
|
|
|
|
paragraph: {
|
|
|
|
spacing: { line: 276 },
|
2020-12-24 03:37:43 +00:00
|
|
|
indent: { left: convertInchesToTwip(0.5) },
|
2019-10-10 01:08:01 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "wellSpaced",
|
|
|
|
name: "Well Spaced",
|
|
|
|
basedOn: "Normal",
|
|
|
|
paragraph: {
|
|
|
|
spacing: { line: 276, before: 20 * 72 * 0.1, after: 20 * 72 * 0.05 },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2021-03-19 20:53:56 +00:00
|
|
|
sections: [
|
|
|
|
{
|
|
|
|
properties: {
|
2021-03-19 21:09:58 +00:00
|
|
|
page: {
|
|
|
|
margin: {
|
|
|
|
top: 700,
|
|
|
|
right: 700,
|
|
|
|
bottom: 700,
|
|
|
|
left: 700,
|
|
|
|
},
|
|
|
|
},
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
|
|
|
footers: {
|
|
|
|
default: new Footer({
|
|
|
|
children: [
|
|
|
|
new Paragraph({
|
|
|
|
text: "1",
|
|
|
|
style: "normalPara",
|
|
|
|
alignment: AlignmentType.RIGHT,
|
|
|
|
}),
|
|
|
|
],
|
2019-09-13 00:51:20 +01:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2019-09-13 00:51:20 +01:00
|
|
|
children: [
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new ImageRun({
|
|
|
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
|
|
|
transformation: {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
2019-09-13 00:51:20 +01:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
text: "HEADING",
|
|
|
|
heading: HeadingLevel.HEADING_1,
|
|
|
|
alignment: AlignmentType.CENTER,
|
2019-09-13 00:51:20 +01:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
text: "Ref. :",
|
|
|
|
style: "normalPara",
|
2019-09-13 00:51:20 +01:00
|
|
|
}),
|
2019-07-31 08:48:02 +01:00
|
|
|
new Paragraph({
|
2021-03-19 20:53:56 +00:00
|
|
|
text: "Date :",
|
2019-07-31 08:48:02 +01:00
|
|
|
style: "normalPara",
|
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
text: "To,",
|
|
|
|
style: "normalPara",
|
2021-03-18 03:28:29 +00:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
text: "The Superindenting Engineer,(O &M)",
|
|
|
|
style: "normalPara",
|
2021-03-18 03:28:29 +00:00
|
|
|
}),
|
2021-03-19 20:53:56 +00:00
|
|
|
new Paragraph({
|
|
|
|
text: "Sub : ",
|
|
|
|
style: "normalPara",
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "Ref. : ",
|
|
|
|
style: "normalPara",
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "Sir,",
|
|
|
|
style: "normalPara",
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "BRIEF DESCRIPTION",
|
|
|
|
style: "normalPara",
|
|
|
|
}),
|
|
|
|
table,
|
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new ImageRun({
|
|
|
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
|
|
|
transformation: {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "Test",
|
|
|
|
style: "normalPara2",
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
children: [
|
|
|
|
new ImageRun({
|
|
|
|
data: fs.readFileSync("./demo/images/pizza.gif"),
|
|
|
|
transformation: {
|
|
|
|
width: 100,
|
|
|
|
height: 100,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
new Paragraph({
|
|
|
|
text: "Test 2",
|
|
|
|
style: "normalPara2",
|
2021-03-18 03:28:29 +00:00
|
|
|
}),
|
|
|
|
],
|
2021-03-19 20:53:56 +00:00
|
|
|
},
|
2019-07-31 08:48:02 +01:00
|
|
|
],
|
2018-03-10 23:04:45 +00:00
|
|
|
});
|
|
|
|
|
2019-08-07 22:12:14 +01:00
|
|
|
Packer.toBuffer(doc).then((buffer) => {
|
2018-08-21 02:46:21 +01:00
|
|
|
fs.writeFileSync("My Document.docx", buffer);
|
|
|
|
});
|