Make .addSection fully declarative
This commit is contained in:
@ -6,21 +6,23 @@
|
||||
To make a bullet point, simply make a paragraph into a bullet point:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Bullet points",
|
||||
bullet: {
|
||||
level: 0 //How deep you want the bullet to be
|
||||
}
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Are awesome",
|
||||
bullet: {
|
||||
level: 0
|
||||
}
|
||||
})
|
||||
],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [
|
||||
new Paragraph({
|
||||
text: "Bullet points",
|
||||
bullet: {
|
||||
level: 0 //How deep you want the bullet to be
|
||||
}
|
||||
}),
|
||||
new Paragraph({
|
||||
text: "Are awesome",
|
||||
bullet: {
|
||||
level: 0
|
||||
}
|
||||
})
|
||||
],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -5,30 +5,32 @@
|
||||
Every Section has a sections which you can define its Headers and Footers:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
headers: {
|
||||
default: new Header({ // The standard default header
|
||||
children: [],
|
||||
}),
|
||||
first: new Header({ // The first header
|
||||
children: [],
|
||||
}),
|
||||
even: new Header({ // The header on every other page
|
||||
children: [],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({ // The standard default footer
|
||||
children: [],
|
||||
}),
|
||||
first: new Footer({ // The first footer
|
||||
children: [],
|
||||
}),
|
||||
even: new Footer({ // The footer on every other page
|
||||
children: [],
|
||||
}),
|
||||
},
|
||||
children: [],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
headers: {
|
||||
default: new Header({ // The standard default header
|
||||
children: [],
|
||||
}),
|
||||
first: new Header({ // The first header
|
||||
children: [],
|
||||
}),
|
||||
even: new Header({ // The header on every other page
|
||||
children: [],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({ // The standard default footer
|
||||
children: [],
|
||||
}),
|
||||
first: new Footer({ // The first footer
|
||||
children: [],
|
||||
}),
|
||||
even: new Footer({ // The footer on every other page
|
||||
children: [],
|
||||
}),
|
||||
},
|
||||
children: [],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -37,20 +37,14 @@ const image = new ImageRun({
|
||||
Add it into the document by adding the image into a paragraph:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [new Paragraph(image)],
|
||||
});
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [image],
|
||||
}),
|
||||
],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [image],
|
||||
}),
|
||||
],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
@ -59,16 +53,22 @@ doc.addSection({
|
||||
Adding images can be easily done by creating an instance of `ImageRun`. This can be added in a `Paragraph` or `Hyperlink`:
|
||||
|
||||
```ts
|
||||
const image = new ImageRun({
|
||||
data: [IMAGE_BUFFER],
|
||||
transformation: {
|
||||
width: [IMAGE_SIZE],
|
||||
height: [IMAGE_SIZE],
|
||||
},
|
||||
});
|
||||
|
||||
doc.addSection({
|
||||
children: [new Paragraph(image)],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [
|
||||
new ImageRun({
|
||||
data: [IMAGE_BUFFER],
|
||||
transformation: {
|
||||
width: [IMAGE_SIZE],
|
||||
height: [IMAGE_SIZE],
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -35,20 +35,24 @@ const paragraph = new Paragraph({
|
||||
After you create the paragraph, you must add the paragraph into a `section`:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [paragraph],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [paragraph],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
Or the preferred convension, define the paragraph inside the section and remove the usage of variables:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Lorem Ipsum Foo Bar"), new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
|
@ -11,12 +11,14 @@ For example, you could have one section which is portrait with a header and foot
|
||||
This creates a simple section in a document with one paragraph inside:
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
@ -35,14 +37,16 @@ Setting the section type determines how the contents of the section will be plac
|
||||
- `ODD_PAGE`
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
properties: {
|
||||
type: SectionType.CONTINUOUS,
|
||||
}
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
properties: {
|
||||
type: SectionType.CONTINUOUS,
|
||||
}
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("Hello World")],
|
||||
}),
|
||||
],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
@ -19,8 +19,10 @@ const table = new Table({
|
||||
Then add the table in the `section`
|
||||
|
||||
```ts
|
||||
doc.addSection({
|
||||
children: [table],
|
||||
const doc = new Document({
|
||||
sections: [{
|
||||
children: [table],
|
||||
}];
|
||||
});
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user