Files
docx-js/demo/26-paragraph-borders.ts

66 lines
2.2 KiB
TypeScript
Raw Normal View History

2018-08-22 00:51:18 +01:00
// Creates two paragraphs, one with a border and one without
// Import from 'docx' rather than '../build' if you install from npm
import * as fs from "fs";
2022-01-06 04:36:55 +00:00
import { BorderStyle, Document, Packer, Paragraph, TextRun } from "../build";
2018-08-22 00:51:18 +01:00
2021-03-19 20:53:56 +00:00
const doc = new Document({
sections: [
{
children: [
new Paragraph("No border!"),
new Paragraph({
text: "I have borders on my top and bottom sides!",
border: {
top: {
color: "auto",
space: 1,
2021-06-18 23:56:41 +01:00
style: BorderStyle.SINGLE,
2021-03-19 20:53:56 +00:00
size: 6,
},
bottom: {
color: "auto",
space: 1,
2023-03-19 15:47:45 +00:00
style: BorderStyle.SINGLE,
size: 6,
},
},
}),
new Paragraph({
text: "",
border: {
top: {
color: "auto",
space: 1,
2021-06-18 23:56:41 +01:00
style: BorderStyle.SINGLE,
2021-03-19 20:53:56 +00:00
size: 6,
},
},
}),
2022-01-06 04:36:55 +00:00
new Paragraph({
children: [
new TextRun({
text: "This will ",
}),
new TextRun({
text: "have a border.",
border: {
color: "auto",
space: 1,
style: BorderStyle.SINGLE,
size: 6,
},
}),
new TextRun({
text: " This will not.",
}),
],
}),
2021-03-19 20:53:56 +00:00
],
},
2019-07-31 08:48:02 +01:00
],
2019-06-17 01:51:57 +01:00
});
2018-08-22 00:51:18 +01:00
2019-08-07 22:12:14 +01:00
Packer.toBuffer(doc).then((buffer) => {
2018-08-22 00:51:18 +01:00
fs.writeFileSync("My Document.docx", buffer);
});