Skip to content

DOCX Generation Fails When Textbox is the First/Only Child in a Paragraph #3193

@DYS1230

Description

@DYS1230

When generating a DOCX file, the document fails to open correctly if a Textbox element is used as the ​​first (or only)​​ child within a Paragraph. The document opens successfully only when the Textbox is preceded by at least one TextRun element in the same paragraph.

Failing Case (Document Corrupted):​

const doc = new Document({
  sections: [{
    properties: {},
    children: [
      new Paragraph({
        children: [
          new Textbox({ // ⚠️ Fails as first child
            alignment: "center",
            children: [new Paragraph({ children: [new TextRun("Hi i'm a textbox!")] })],
            style: { width: "200pt", height: "auto" }
          })
        ]
      })
    ]
  }]
});

Working Case (Document Opens):​

const doc = new Document({
  sections: [{
    properties: {},
    children: [
      new Paragraph({
        children: [
          new TextRun("Hello World"), // ✅ Required before Textbox
          new Textbox({
            alignment: "center",
            children: [new Paragraph({ children: [new TextRun("Hi i'm a textbox!")] })],
            style: { width: "200pt", height: "auto" }
          })
        ]
      })
    ]
  }]
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions