Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setting the heading to TITLE in first paragraph causes other paragraph to inherit the heading style of first paragraph #2722

Open
shyamayadav154 opened this issue Sep 10, 2024 · 0 comments

Comments

@shyamayadav154
Copy link

shyamayadav154 commented Sep 10, 2024

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);
});
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant