html_to_pdf tool, the quality of your output depends entirely on how well the HTML is structured for print. The PDF Best Practices skill provides AI assistants with comprehensive guidelines to create professional, well-formatted PDF documents.
Installing the Skill
The PDF Best Practices skill is available as a standalone package that AI assistants can reference.- npx skills (Recommended)
- npm
- Direct Reference
Install as an agent skill:This makes the skill available to AI coding assistants that support the skills protocol.
What the Skill Covers
The skill includes 8 comprehensive guides:Document Setup
HTML structure, base CSS, A4 specifications, and typography defaults.
Page Breaks
Control where content splits with
page-break-inside, break-after, and orphan/widow handling.Tables
Proper
thead/tbody structure, header repetition, column widths, and zebra striping.Images
Explicit dimensions,
object-fit, figures with captions, and image galleries.Content Density
Avoid sparse pages, flexible spacing, and content reflow strategies.
Colors & Backgrounds
The critical
-webkit-print-color-adjust: exact property and contrast guidelines.Headers & Footers
Document headers, page numbers via
footerTemplate, and letterhead patterns.Document Types
Specific guidelines for invoices, reports, certificates, letters, and more.
Default Configuration
The skill recommends these PDF parameters:A4 Paper Specifications
| Property | Value |
|---|---|
| Width | 210mm (794px at 96 DPI) |
| Height | 297mm (1123px at 96 DPI) |
| Safe content width | ~714px (with 40px margins) |
| Safe content height | ~1043px per page |
Essential CSS Rules
Every HTML-to-PDF document should include these CSS rules:Page Break Control
Prevent awkward content splits with these CSS properties:When to Use Page Breaks
Use page-break-inside: avoid on | Use page-break-before: always on |
|---|---|
| Cards and content boxes | Chapter starts |
| Table rows | Major sections |
| Figures with captions | New document parts |
| List items with multiple lines | Title pages |
Table Formatting
Tables require special attention for multi-page documents:Image Handling
Always specify explicit dimensions for images:Image Guidelines
- Use absolute URLs (https://…) for all images
- Set max-height to 300-400px to fit well on pages
- Group images with captions using
<figure> - Use
object-fit: containto preserve aspect ratios
Content Density
Avoid pages with minimal content by:- Estimating content height before structuring documents
- Grouping related content to flow naturally
- Using flexible spacing instead of fixed large gaps
- Reducing margins slightly if the last page is sparse
Reflow Strategies
If the last page has less than 25% content:- Reduce margins: 35px instead of 40px
- Tighten line-height: 1.4 instead of 1.5
- Reduce section margins
- Use slightly smaller font for dense data (11pt)
Document Type Guidelines
The skill includes specific recommendations for common document types:Invoice
Invoice
- Keep entire invoice on one page if possible
- Right-align all monetary values
- Use clear table for line items
- Include totals section that stays with items table
- Add payment terms prominently
Report
Report
- Use title page for documents over 3 pages
- Include table of contents
- Page breaks before major sections
- Consistent heading hierarchy
- Executive summary at start
Certificate
Certificate
- Center all content
- Larger fonts (18-36pt)
- Decorative borders
- Single page only
- Consider landscape orientation
Letter
Letter
- Standard business letter format
- Letterhead with logo
- Clear date and recipient block
- Signature area at bottom
- 1-2 pages maximum