Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Set a custom DOCX page size on each section with python-docx, or pass a (width, height) tuple in points to ReportLab when generating a PDF. Set dimensions, orientation, and margins together, subtract margins before laying out content, and inspect the finished file in the viewer or print workflow you will use.

Choose DOCX, PDF, or both

Use DOCX first when people must edit the file in Microsoft Word, apply Word styles, or supply comments and tracked changes. Use a PDF generated directly when the final artifact needs deterministic page geometry and should not depend on a later editing step. If you need both, generate separate outputs and validate each one: conversion engines can paginate differently because of font availability, line wrapping, and layout rules.

Requirement Best starting point Reason
Editable Word document python-docx Creates editable Word 2007+ .docx files.
Fixed-size final document ReportLab The PDF page box is specified directly in points.
Complex flowing PDF ReportLab Platypus Flowables handle paragraphs, tables, and multi-page layout.
Precise drawing or a single page ReportLab canvas Low-level coordinates give direct control.

Create a custom-size DOCX with python-docx

Install the library in the environment that will run the script:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python -m pip install python-docx

Page dimensions are section properties. The following complete script creates a 6-by-9-inch portrait document, applies explicit margins, adds content, and saves it.

#1 Best Overall
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
  • Convert over 50 document file formats.
  • Preview your files from Doxillion before converting them.
  • Use batch conversion to convert thousands of files at once.
  • Enjoy an easy-to-use, intuitive interface with a Drag and Drop file option.
  • Burn your converted or original files directly to disc.
from docx import Document
from docx.shared import Inches
from docx.enum.section import WD_ORIENT

doc = Document()
section = doc.sections[0]

# Keep width and height in the same unit and set orientation explicitly.
section.page_width = Inches(6)
section.page_height = Inches(9)
section.orientation = WD_ORIENT.PORTRAIT

section.top_margin = Inches(0.6)
section.bottom_margin = Inches(0.6)
section.left_margin = Inches(0.7)
section.right_margin = Inches(0.7)

doc.add_heading("Custom-size DOCX", level=1)
doc.add_paragraph("This text is laid out inside the usable area of a 6 × 9 inch page.")
doc.save("custom.docx")

Landscape pages

Set the intended dimensions and orientation as one operation. For a 9-by-6-inch landscape page:

from docx import Document
from docx.shared import Inches
from docx.enum.section import WD_ORIENT

doc = Document()
section = doc.sections[0]
section.page_width = Inches(9)
section.page_height = Inches(6)
section.orientation = WD_ORIENT.LANDSCAPE
section.top_margin = Inches(0.5)
section.bottom_margin = Inches(0.5)
section.left_margin = Inches(0.5)
section.right_margin = Inches(0.5)
doc.add_paragraph("Landscape content")
doc.save("landscape.docx")

Some Word examples swap width and height when changing orientation. The important rule is consistency: the width and height you assign must describe the page you intend, and the orientation must agree with them. Do not rely on an implicit swap.

Mixed sizes in one DOCX

A page size is not a document-wide setting; it belongs to a section. Add a new section before configuring a different page:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from docx import Document
from docx.shared import Inches
from docx.enum.section import WD_SECTION, WD_ORIENT

doc = Document()
first = doc.sections[0]
first.page_width = Inches(8.5)
first.page_height = Inches(11)
first.orientation = WD_ORIENT.PORTRAIT
doc.add_paragraph("Letter-sized section")

second = doc.add_section(WD_SECTION.NEW_PAGE)
second.page_width = Inches(11)
second.page_height = Inches(8.5)
second.orientation = WD_ORIENT.LANDSCAPE
second.left_margin = Inches(0.5)
second.right_margin = Inches(0.5)
doc.add_paragraph("Landscape section")
doc.save("mixed-size.docx")

Configure every new section independently, including its margins. Content can still inherit other Word section settings, so inspect the result in Word or another DOCX viewer.

Rank #2
Doxillion Free Document Converter for Mac – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
  • Convert over 50 document file formats.
  • Preview your files from Doxillion before converting them.
  • Use batch conversion to convert thousands of files at once.
  • Enjoy an easy-to-use, intuitive interface with a Drag and Drop file option.
  • Burn your converted or original files directly to disc.

Create a custom-size PDF directly with ReportLab

Install ReportLab:

python -m pip install reportlab

ReportLab’s canvas accepts pagesize=(width, height) in points; one point is 1/72 inch. Standard constants such as letter and A4 are available, but custom dimensions are just as valid.

from reportlab.pdfgen import canvas
from reportlab.lib.units import inch

width = 6 * inch
height = 9 * inch
pdf = canvas.Canvas("custom.pdf", pagesize=(width, height))
pdf.drawString(0.5 * inch, height - 0.75 * inch, "Custom-size PDF")
pdf.showPage()
pdf.save()

Coordinates start at the lower-left corner. In the example, the text baseline is positioned from the top by subtracting from the page height. Drawing outside the page is clipped or invisible, so keep every coordinate inside the page box.

Margins and usable dimensions

A custom page box does not automatically create a content area. Calculate usable dimensions before placing text or graphics:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from reportlab.pdfgen import canvas
from reportlab.lib.units import mm

page_w = 120 * mm
page_h = 180 * mm
margin = 12 * mm

pdf = canvas.Canvas("ticket.pdf", pagesize=(page_w, page_h))
usable_w = page_w - 2 * margin
usable_h = page_h - 2 * margin
pdf.drawString(margin, page_h - margin, "Top-left area")
pdf.rect(margin, margin, usable_w, usable_h)
pdf.showPage()
pdf.save()

Use one source of truth for dimensions and label the units in code. Convert millimetres or inches to points before passing values to ReportLab.

Rank #3
PDF To Word - PDF Converter
  • - Convert to Word/Excel: Select your PDF and effortlessly convert it to Word or Excel.
  • - Mobile Convenience: Manage your PDFs on the go with our intuitive PDF expert.
  • - Free PDF Conversion: Experience the power of our PDF converter with complimentary conversions.

Use Platypus for flowing, multi-page PDFs

Canvas is ideal for deliberate coordinates, but long prose, tables, and repeated page structures are easier with ReportLab Platypus. A document template defines the page size and a frame defines the usable region. Flowables then fill that frame and continue onto new pages.

from reportlab.lib.pagesizes import portrait
from reportlab.lib.styles import getSampleStyleSheet
from reportlab.lib.units import inch
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer

page_w, page_h = 6 * inch, 9 * inch
margin = 0.6 * inch
styles = getSampleStyleSheet()

pdf = SimpleDocTemplate(
    "flowing.pdf",
    pagesize=(page_w, page_h),
    leftMargin=margin,
    rightMargin=margin,
    topMargin=margin,
    bottomMargin=margin,
)
story = [
    Paragraph("A flowing custom-size PDF", styles["Title"]),
    Spacer(1, 12),
    Paragraph("Paragraphs wrap within the frame and continue across pages when necessary.", styles["BodyText"]),
]
pdf.build(story)

For headers, footers, or marks that must be positioned precisely, use canvas callbacks while Platypus manages the flowable content.

Units, orientation, and layout rules that prevent failures

  • Keep width and height ordered. Document the order in variables such as page_width and page_height; do not pass a height where a width is expected.
  • Set orientation with dimensions. Portrait and landscape are not substitutes for assigning the correct geometry.
  • Subtract margins. Text, tables, and images must fit inside usable width and height, not merely inside the outer page box.
  • Wrap or split content. A long unbreakable string, wide table, or oversized image can still overflow a perfectly valid page.
  • Account for fonts. Different installed fonts change line wrapping and therefore pagination, especially after DOCX-to-PDF conversion.
  • Use explicit page sizes. Avoid relying on a viewer, printer driver, or conversion tool to infer a non-standard size.

Validate the generated files

  1. Open the DOCX in the target Word-compatible application and check every section’s size and orientation.
  2. Open the PDF and inspect each page, including the first and last content lines, tables, images, headers, and footers.
  3. Confirm that the viewer reports the intended physical dimensions, not a nearby standard size.
  4. Print or export through the actual production path and verify that no driver scales, clips, or adds margins.
  5. For converted files, compare page breaks, font substitutions, and line wrapping with the source document.

Troubleshooting common problems

The page is the wrong shape

Check width and height order, unit conversion, and orientation together. In DOCX, inspect the specific section rather than only the first page. In PDF, verify the tuple passed to Canvas or the Platypus template.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Text or graphics disappear at the edge

The drawing lies outside the page or usable frame. Reduce coordinates by the margins, wrap long lines, resize images, or split a table across pages.

Rank #4
Image to PDF Converter
  • All item converter to pdf

Landscape content is rotated or squeezed

Set landscape dimensions explicitly and ensure the layout code uses the same width and height variables. Do not rotate content while leaving a portrait page box.

Only the first section has the custom size

DOCX dimensions are section-scoped. Create and configure a new section for each different size; do not assume a later section inherits the geometry you want.

DOCX and PDF pagination differs

That is expected across conversion engines when fonts, line metrics, or layout implementations differ. Embed or standardize fonts where your workflow permits, then inspect the converted PDF rather than assuming identical breaks.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Tables overflow a PDF frame

Compute the frame width after margins, reduce column widths or font size, and use a Platypus table that can split across pages. Canvas does not automatically reflow a table.

Best Value
OfficeSuite: Word documents, Excel Sheets, PowerPoint Slides & PDF Editor & Converter
  • All-in-one office pack - Documents, Sheets, Slides & PDF
  • Cross-platform (Android, iOS, Windows PC)
  • Supports Microsoft Office formats
  • Use 30+ charts & 250+ formulas in Sheets
  • In-depth features for document creation & formatting
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a clean visual preview of a generated document or a web-based rendition, ScreenshotNeo can capture a URL through one request. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

See the ScreenshotNeo API documentation for options such as full-page capture, element selection, device and retina settings, PDF paper size and margins, custom CSS or JavaScript, waits, blocked resources, cookies, headers, geolocation, caching, signed links, webhooks, and bulk capture.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots, and every feature is available on every plan. Create a free ScreenshotNeo account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

Can one DOCX contain portrait and landscape pages?

Yes. Create a separate section for each geometry and configure that section’s dimensions, orientation, and margins.

What unit does ReportLab use for page sizes?

Canvas page dimensions are points, with 72 points per inch. Convert inches or millimetres before constructing the page-size tuple.

Should I use canvas or Platypus?

Use canvas for precise coordinate drawing; use Platypus when paragraphs, tables, and repeated multi-page structures must flow automatically.

Quick Recap

Bestseller No. 1
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Doxillion Free Document Converter – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Convert over 50 document file formats.; Preview your files from Doxillion before converting them.
Bestseller No. 2
Doxillion Free Document Converter for Mac – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Doxillion Free Document Converter for Mac – Converts DOCX, DOC, PDF, WPS and Many More Files Quickly [Download]
Convert over 50 document file formats.; Preview your files from Doxillion before converting them.
Bestseller No. 3
PDF To Word - PDF Converter
PDF To Word - PDF Converter
- Convert to Word/Excel: Select your PDF and effortlessly convert it to Word or Excel.; - Mobile Convenience: Manage your PDFs on the go with our intuitive PDF expert.
Bestseller No. 4
Image to PDF Converter
Image to PDF Converter
All item converter to pdf
Bestseller No. 5
OfficeSuite: Word documents, Excel Sheets, PowerPoint Slides & PDF Editor & Converter
OfficeSuite: Word documents, Excel Sheets, PowerPoint Slides & PDF Editor & Converter
All-in-one office pack - Documents, Sheets, Slides & PDF; Cross-platform (Android, iOS, Windows PC)

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.