docx
docx copied to clipboard
setting the heading to TITLE in first paragraph causes other paragraph to inherit the heading style of first paragraph
issue : setting the heading to TITLE in first paragraph causes other paragraph to inherit the heading style of first paragraph
code to generate the error:
const docx = require('docx');
const fs = require('fs');
// Create a new document
const doc = new docx.Document({
sections: [{
properties: {},
children: [
new docx.Paragraph({
text: "Document Title",
heading: docx.HeadingLevel.TITLE,
alignment: docx.AlignmentType.CENTER,
}),
new docx.Paragraph({
text: "",
spacing: {
before: 2000, // Adjust this value to move the content vertically
},
}),
new docx.Paragraph({
children: [
new docx.TextRun({
text: "This is the first centered paragraph.",
}),
],
alignment: docx.AlignmentType.CENTER,
}),
new docx.Paragraph({
children: [
new docx.TextRun({
text: "This is the second centered paragraph.",
}),
],
alignment: docx.AlignmentType.CENTER,
spacing: {
before: 200, // Add some space between paragraphs
},
}),
new docx.Paragraph({
children: [
new docx.TextRun({
text: "This is the third centered paragraph.",
}),
],
alignment: docx.AlignmentType.CENTER,
spacing: {
before: 200,
},
}),
],
}],
});
// Generate the document
docx.Packer.toBuffer(doc).then((buffer) => {
fs.writeFileSync("centered_paragraphs_with_title.docx", buffer);
});