All prompts
Document generation Intermediate

Print-ready PDFs with PRINT.md

Use PRINT.md to control page breaks, repeating headers and footers, page counters, and tables that span multiple pages

printcsspage-breaksheadersfooterspage-counter

What this recipe covers

Common print CSS problems include overflowing content, tables that lose their headers, missing page numbers, and absent document headers or footers. PRINT.md covers @page rules, margin boxes, break control, and tables that span multiple pages. Link or attach it so the agent can refer to the full guide.

The examples below show how to reference PRINT.md for common document layouts.

Use PRINT.md in a prompt

Ask the agent to fetch or refer to the guide:

Attach PRINT.md
Use the CSS print styling guide at https://pdf-mcp.io/PRINT.md as reference for all CSS in this document.

Create [describe your document] as HTML with the required print CSS, then call html_to_pdf to render it.

If your MCP client supports file attachments, you can attach PRINT.md to the conversation instead of linking to it.

Page breaks

Use break controls to keep related content together or start chapters and sections on new pages.

Page break control
Create a multi-section HTML report, then use pdf-mcp to render it as a PDF.

Use the print CSS guide at https://pdf-mcp.io/PRINT.md as reference.

Page break requirements:
- Each major section starts on a new page (break-before: page)
- Headings never appear alone at the bottom of a page (break-after: avoid)
- Figures, code blocks, and key-value groups never split across pages (break-inside: avoid)
- Use both modern (break-*) and legacy (page-break-*) properties for compatibility
- Reset floats in @media print so breaks work on all elements

Content:
[Describe your document sections here]

Call html_to_pdf with the completed HTML.

CSS @page margin boxes can add the same header and footer to every page without JavaScript.

Header and footer
Create an HTML document with a running header and footer on every page, then use pdf-mcp to render it as a PDF.

Use the print CSS guide at https://pdf-mcp.io/PRINT.md as reference for @page margin boxes.

Header/footer requirements:
- @page top-left: company name or logo
- @page top-right: document title
- @page bottom-left: "Confidential" or a disclaimer
- @page bottom-right: "Page X of Y" using counter(page) and counter(pages)
- First page: no header (use @page :first to override)
- Margin: 2.5cm top/bottom to leave room for margin box content

Document details:
Company: [Company Name]
Title: [Document Title]
Content: [Describe your document here]

Call html_to_pdf with the completed HTML.

Dynamic page counter

Use CSS counters to number pages automatically.

Page counter
Create an HTML document with page numbering, then use pdf-mcp to render it as a PDF.

Use the print CSS guide at https://pdf-mcp.io/PRINT.md as reference for page counters.

Page numbering requirements:
- Bottom center of every page: "Page X of Y"
- Use @page { @bottom-center { content: "Page " counter(page) " of " counter(pages); } }
- First page should show page number 1 (no special treatment)
- Font size 9pt, gray color for the counter

Document:
[Describe your document here]

Call html_to_pdf with the completed HTML.

Multi-page tables

Repeat table headers on each page and keep individual rows from splitting.

Multi-page table
Create an HTML data table with the pagination rules below, then use pdf-mcp to render it as a PDF.

Use the print CSS guide at https://pdf-mcp.io/PRINT.md as reference for table handling.

Table requirements:
- thead { display: table-header-group; } to repeat column headers on every page
- tfoot { display: table-footer-group; } for a repeating footer row
- tr { break-inside: avoid; page-break-inside: avoid; } so rows never split
- @page with enough margin for readability
- Alternating row colors for readability

Table data:
[Describe your table columns and data here]

Call html_to_pdf with the completed HTML.

One prompt for a complete document

This prompt combines headers, footers, page counters, page breaks, and multi-page tables.

Complete print-ready document
Create a report as a complete HTML document with the print CSS below, then use pdf-mcp to render it as a PDF.

Use the print CSS guide at https://pdf-mcp.io/PRINT.md as reference.

Print CSS requirements:
1. @page: A4, 2.5cm margins on all sides
2. Header: company name top-left, document title top-center
3. Footer: "Confidential" bottom-left, "Page X of Y" bottom-right
4. First page: hide the centered header (@page :first { @top-center { content: none; } })
5. Sections: each major section starts on a new page
6. Headings: never orphaned at page bottom
7. Tables: thead repeats on every page, rows never split
8. Images: max-width 100%, never split across pages
9. Paragraphs: orphans: 3, widows: 3

Document details:
Company: [Company Name]
Title: [Document Title]
Sections: [List your sections and content]

Call html_to_pdf with the completed HTML.

Tips

  • Attach or link PRINT.md so the agent has the complete CSS paged media reference.
  • Specify each margin-box position and its content, such as a company name in @top-left or a page counter in @bottom-right, instead of asking only for “a header.”
  • Pair break-before: page with page-break-before: always for compatibility.
  • Leave at least 2.5cm of space in the top and bottom @page margins so headers and footers do not overlap the content.
  • Test with enough content to fill at least two pages. Page breaks and repeating headers cannot be checked on a single page.