Set the paper size, margins and orientation of any URL to PDF
Set the PDF paper size, the margins and the orientation per request, so the same endpoint prints an A4 report, a Letter memo, a landscape dashboard or a receipt-sized ticket. A PDF is a printed layout decision: which paper, how much whitespace, portrait or landscape, how much content per page. The PDF API exposes each of those as an option.
One default PDF paper size cannot fit every document
A wide dashboard printed portrait gets crushed into a column. A receipt on A4 wastes most of the sheet. A long article with almost no margin is unreadable once it reaches a printer, and a US customer expects Letter where a European one expects A4.
Browsers pick one default and hide the rest behind a print dialog, which is no help to a backend job. CSS @page rules only work when you control the target page, and most HTML-to-PDF libraries make you restate the layout in their own configuration for every document type.
Microlink’s PDF options map straight to the printed layout: pdf.format for standard paper, pdf.width and pdf.height for exact dimensions, pdf.margin per side, pdf.landscape for wide content, pdf.scale to fit more or less per page, and pdf.pageRanges to keep only the pages you want.
How to set PDF paper size, margins and orientation
Use one sizing strategy at a time: a named format for office documents, or width and height for custom media. Margins, orientation and scale compose with either. The page size and layout guide has a live example of each option.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { url } = await microlink.pdf('https://example.com/report', {
format: 'A4',
margin: { top: '12mm', bottom: '16mm', left: '10mm', right: '10mm' }
})A4 with asymmetric margins is the common setup for printed reports: extra room at the bottom for page numbers or binding. In the SDK the PDF options are flat; in a raw URL they use dot notation such as pdf.format=A4.
import createClient from 'microlink.io'
const microlink = createClient({
apiKey: process.env.MICROLINK_API_KEY
})
const { url } = await microlink.pdf('https://example.com/dashboard', {
format: 'Letter',
landscape: true,
scale: 0.8,
pageRanges: '1-2',
printBackground: true
})Landscape stops a wide table from being squeezed, scale 0.8 enlarges the content over the 0.6 default, and pageRanges keeps a two-page preview. printBackground includes background colors and images in the output.
curl 'https://api.microlink.io/?url=https%3A%2F%2Fexample.com%2Fticket&pdf.width=80mm&pdf.height=200mm&pdf.margin=4mm&meta=false'Exact dimensions for receipts, labels or tickets, expressed in px, in, cm or mm. meta=false skips metadata extraction, which is usually the biggest speedup for a PDF-only request.
- pdf.format Letter, Legal, Tabloid, Ledger or A0 to A6. Default A4.
- pdf.width Custom paper width with a unit; use it with height instead of format.
- pdf.height Custom paper height with a unit.
- pdf.margin One value for all sides or an object with top, right, bottom and left. Default 0.35cm.
- pdf.landscape Landscape orientation for wide tables, dashboards and comparison pages.
- pdf.scale Rendering zoom between 0.1 and 2. Default 0.6.
- pdf.pageRanges Pages to keep, such as 1-5, 8, 11-13 or 5- for an open end. Out-of-range values fail with EPAGERANGE.
Units are the CSS ones: px, in, cm and mm. Layout options shape the paper, not the page, so pair them with mediaType when you need the on-screen design instead of the print stylesheet.
Why paper size and margins belong in the request
Paper decisions change per document, not per integration. Passing them per request keeps one endpoint serving every format, from invoices to A0 posters.
Formats and custom sizes are alternatives by design; pick the one that expresses what the document is.
The default margin is 0.35cm, which suits screen viewing; move to 1cm or more for anything that reaches a printer. For charts that render late, combine landscape with the waits in PDFs of JavaScript-rendered pages.
When not to: if the page itself is not paginated content, such as an infinite feed, a screenshot with fullPage may represent it better than a PDF.
FAQ
Which PDF paper formats are supported?
Can I set different PDF margins per side?
How do I export only some pages of the PDF?
What does pdf.scale change in the generated PDF?
How do I create a PDF with a custom page size, like a receipt or a label?
Solve the next problem with the same API
Clean PDFs without ads or banners
PDF invoices from authenticated pages
PDFs of JavaScript-rendered pages
Ready to print on the right paper?
Format, margins, orientation and scale in one request. Start on the free tier and print your first A4 or Letter document today.