docx/page-orientation-landscape

Section page size set to landscape orientation via <w:pgSz w:orient="landscape"/>.

Library verdicts: python-docx: — docxjs: fail

Metadata

Feature iddocx/page-orientation-landscape
Formatdocx
Categorypage-layout
Spececma-376-5-part-1 § 17.6.11 w:pgSz

XPath assertions

ID / partPredicateXPathpython-docxdocxjs
pgSz-present
word/document.xml
exist
The section must carry a <w:pgSz> element.
//w:sectPr/w:pgSz
pgSz-orient-landscape
word/document.xml
equal = landscape
w:pgSz@w:orient must be exactly 'landscape'.
//w:sectPr/w:pgSz/@w:orient

Render assertions

IDPredicateSelectorpython-docxdocxjs
landscape-text-presentcss_selector/ match-text = Landscape page
Smoke check: the fixture body text must appear in the rendered DOM. Most HTML renderers do not visibly indicate page orientation; a stricter computed-style assertion would be unrealistic here.
.docx-wrapper ppass
landscape-marker-presentcss_selector/ exist
If the renderer exposes orientation metadata, a landscape marker must be present. Many renderers omit this — the assertion is expected to fail for those libraries and land as a meaningful gap.
.docx-wrapper [data-orientation='landscape'], .docx-wrapper .page-landscape, .docx-wrapper .page[data-orient='landscape']fail

Generator source

scripts/gen_page_orientation_landscape.py

#!/usr/bin/env python3
"""Generate ``fixtures/docx/page-orientation-landscape.docx``.

A minimal document exercising landscape page orientation. Sets the
default section's orientation to landscape and swaps page width/height
so the rendered page actually reflects the orientation flag. Designed
to satisfy the assertions in
``features/docx/page-orientation-landscape.json``.
"""

from __future__ import annotations

from pathlib import Path

from docx import Document
from docx.enum.section import WD_ORIENTATION

_REPO_ROOT = Path(__file__).resolve().parent.parent
_OUT = _REPO_ROOT / "fixtures" / "docx" / "page-orientation-landscape.docx"


def main() -> int:
    doc = Document()
    section = doc.sections[-1]
    section.orientation = WD_ORIENTATION.LANDSCAPE
    # Also swap page width/height to match the landscape intent; Word
    # renders portrait pages regardless of @w:orient unless the
    # dimensions match.
    section.page_width, section.page_height = section.page_height, section.page_width
    doc.add_paragraph("Landscape page")
    _OUT.parent.mkdir(parents=True, exist_ok=True)
    doc.save(_OUT, reproducible=True)
    print(_OUT)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())

Manifest (expanded)

{
  "$schema": "../manifest.schema.json",
  "id": "docx/page-orientation-landscape",
  "title": "Page orientation — landscape",
  "format": "docx",
  "category": "page-layout",
  "summary": "Section page size set to landscape orientation via <w:pgSz w:orient=\"landscape\"/>.",
  "spec": {
    "source": "ecma-376-5-part-1",
    "clause": "17.6.11",
    "element": "w:pgSz",
    "rnc_reference": "spec/ecma-376-5/part-1/rnc/WordprocessingML.rnc",
    "xsd_reference": "spec/ecma-376-5/part-1/xsd/wml.xsd",
    "notes": "Page orientation is carried by @w:orient on <w:pgSz> inside <w:sectPr>. When landscape, @w:w and @w:h should be swapped relative to the default portrait dimensions; writers that only set @w:orient leave the rendered page ambiguous."
  },
  "fixtures": {
    "machine": "docx/page-orientation-landscape",
    "office": "docx/page-orientation-landscape"
  },
  "generator": {
    "python": "scripts/gen_page_orientation_landscape.py"
  },
  "assertions": [
    {
      "id": "pgSz-present",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:sectPr/w:pgSz",
      "must": "exist",
      "description": "The section must carry a <w:pgSz> element."
    },
    {
      "id": "pgSz-orient-landscape",
      "part": "word/document.xml",
      "namespaces": {
        "w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"
      },
      "xpath": "//w:sectPr/w:pgSz/@w:orient",
      "must": "equal",
      "value": "landscape",
      "description": "w:pgSz@w:orient must be exactly 'landscape'."
    }
  ],
  "render_assertions": [
    {
      "id": "landscape-text-present",
      "kind": "css_selector",
      "selector": ".docx-wrapper p",
      "must": "match-text",
      "value": "Landscape page",
      "description": "Smoke check: the fixture body text must appear in the rendered DOM. Most HTML renderers do not visibly indicate page orientation; a stricter computed-style assertion would be unrealistic here."
    },
    {
      "id": "landscape-marker-present",
      "kind": "css_selector",
      "selector": ".docx-wrapper [data-orientation='landscape'], .docx-wrapper .page-landscape, .docx-wrapper .page[data-orient='landscape']",
      "must": "exist",
      "description": "If the renderer exposes orientation metadata, a landscape marker must be present. Many renderers omit this — the assertion is expected to fail for those libraries and land as a meaningful gap."
    }
  ]
}

Fixture

Download page-orientation-landscape.docx (18.6 KB)

Reference preview

Reference (machine, page 1 PNG)

docx/page-orientation-landscape page 1 reference

Reference PDF


Download PDF Open in PDF.js

Spec notes

Page orientation is carried by @w:orient on <w:pgSz> inside <w:sectPr>. When landscape, @w:w and @w:h should be swapped relative to the default portrait dimensions; writers that only set @w:orient leave the rendered page ambiguous.