Processed on-device · pdf.js + pdf-lib

Add Margins to PDF Online — set custom top, bottom, left, and right margins

Set top, bottom, left, and right margins in millimeters, inches, or pixels — expand the page to add room, or scale content down to fit within it.

See the four steps
Four-side margin control mm, inch, or px units Expand or scale-to-fit PDF processing stays in your browser
Built & maintained by Bhavin J. Sheth | Updated

Add margins to your PDF

Upload a PDF, set your margins, choose how they are applied, and download the result.

Drop your PDF here

or browse files

How margins work

Margins are just numbers around a page

A PDF page has defined dimensions that determine the space available for its content. This tool adds space around that content or scales it to fit within the existing page.

Two ways to make room

A printer that needs gutter space, a binder that trims a chunk off the inside edge of every page, a reviewer who wants blank space to write comments in — each of these needs extra room around a document's content, but for different reasons and in different amounts.

pdf-lib reads each page's current dimensions, then either draws a larger page and places the original content inside it at an offset (Expand), or scales the content down and repositions it within the existing page boundary (Keep Size). Units convert to points internally — 1mm = 2.835 points, 1 inch = 72 points — so the same margin looks identical regardless of which unit you typed it in.

Every control and what it changes

Four independent sides

Set top, bottom, left, and right separately — a document rarely needs the same margin on every edge.

mm, inch, or px

Choose the unit that matches your document specifications — the tool converts internally.

Mirror margins

Automatically swaps left/right on alternating pages, so binding margins line up correctly through a printed booklet.

Page range

Apply the same margin to every page, or only to a specific range you type in.

Expand vs. Keep Size

Grow the page to fit new margins, or scale the content to fit inside the current page.

Step-by-step margin configuration

Choose the unit first, then enter the margin values for each side.

1

Upload your PDF

Drag it onto the upload area, or click Select PDF. Thumbnails of every page load right away.

The margin controls appear as soon as the file loads.
2

Set margin size and mode

Configure the four sides and how they're applied:

Top/Bottom/Left/Right: set independently, or click a preset.
Unit: Choose millimeters, inches, or pixels based on your document specs.
Mode: Expand Page Size or Keep Page Size.
3

Apply

Click Add Margins. Every selected page is rebuilt with the new spacing in this tab.

PDF processing stays in your browser — files are not uploaded to an external server.
4

Check and download

Page through the result to confirm the spacing looks right, then download.

Full-file preview Original proportions preserved

From tight pages to properly spaced

A document with content running right to the edge, expanded with even margins on all sides.

Original No margin
Original PDF page with content running to the edge before adding margins

Content reaches the page edge, leaving little room for printer margins, binding, or handwritten notes.

Margins added
With margins Even spacing
PDF page with even margins added on all four sides

Even white space on every side — useful for printing, binding, or adding handwritten notes.

Margin modes explained

Two modes, two different outcomes

Same margin values, two very different results — pick based on whether page size matters.

Expand page size

Adds the margin as new white space around your existing content — the page gets physically larger. A US Letter page with 20mm margins added becomes larger than Letter. Right for printing, binding, or anywhere the original content size must stay untouched.

Keep page size

Scales your content down proportionally so it fits inside the same page dimensions, with the margin as empty border. Right when a form or template requires an exact page size (like A4 or Letter) that can't change.

Mirror margins

Swaps left and right margins on alternating pages, so the "inside" edge (the one lost to binding) gets the wider margin on every page — the standard setup for a printed book or booklet.

Page range

Applies the margin change to every page, or only to a range you specify — useful when only a section of a larger document needs different spacing.

Documents that need room around the content

Cases where extra space at the edges solves a real printing, binding, or reading problem.

Common situations for adding margins to a PDF, by user type
SituationWhat margins solveTypical user
Home & office printingAdd safe margins so a printer with limited edge coverage doesn't clip content.Offices & students
Book & booklet bindingUse Mirror Margins to leave gutter room on the inside edge for stapling or perfect binding.Publishers & print shops
Peer review & annotationAdd blank space around content for handwritten comments or stamps.Editors & reviewers
Academic formattingMeet a university or journal's required margin specifications before submission.Students & researchers
Legal filingsAdjust document margins to meet a specified filing requirement; verify the applicable rules before submission.Lawyers & paralegals
Scanned document cleanupStandardize inconsistent margins across pages scanned from different sources.Archivists & admins
Presentation handoutsAdd note-taking space around slide content for printed handouts.Presenters & trainers
Design proofingAdd extra safe space around page content before sending a document to print.Designers

When the margins don't come out right

Common margin problems, why they happen, and how to fix them.

Symptom
Why it happens
Fix

Margins look much bigger or smaller than expected

The unit dropdown was left on the wrong setting — 20 inches is very different from 20mm.

Double-check the unit selector matches the numbers you typed, then re-run.

Content looks too small after adding margins

Keep Page Size mode was used with large margin values, shrinking the content a lot to fit.

Switch to Expand Page Size if the original content size matters, or reduce the margin values.

Output page size is now non-standard

Expand Page Size grows the page beyond a standard size like A4 or Letter.

Expected behavior — use Keep Page Size instead if the exact dimensions must stay standard.

Binding margin is on the wrong side of some pages

Mirror Margins wasn't enabled, so left and right stayed fixed instead of alternating.

Turn on the Mirror Margins checkbox before applying, then re-run.

Only some pages got the new margins

Page Range was selected but the typed range didn't cover the pages you meant.

Check the page range field, or switch to All Pages to apply it everywhere.

A password-protected PDF won't load

Encrypted files can't be read by the in-browser rendering engine.

Remove the PDF password first with our PDF Unlock tool, then upload the unlocked copy.

Margins look wrong size

Why: Wrong unit selected.

Fix: Check the unit dropdown, re-run.

Content too small

Why: Keep Page Size with large margins.

Fix: Use Expand Page Size instead.

Non-standard output size

Why: Expand mode grows the page.

Fix: Use Keep Page Size instead.

Wrong-side binding margin

Why: Mirror Margins was off.

Fix: Turn it on, re-run.

Only some pages changed

Why: Page range didn't cover them.

Fix: Check the range or use All Pages.

Password-protected PDF won't load

Why: Encrypted files can't decode in-browser.

Fix: Unlock it first, then upload.

Getting margins right on the first pass

A working order that avoids the most common redo.

Confirm the unit before typing numbers

Set mm, inch, or px first — it's the setting most likely to produce a wildly wrong result if overlooked.

Choose the mode based on what must stay fixed

Use Expand when you want to preserve the original content size. Use Keep Size when the final page dimensions must remain unchanged, such as A4 or Letter.

Turn on Mirror Margins for booklets

Documents with an inside binding edge may need alternating margins — enable this when the wider margin should move between left and right pages.

Try a preset first

Narrow, Normal, Wide, and Binding presets cover most common cases — start there before entering custom values.

Preview one page before processing all

Check the output preview carefully on the first result — it's much faster to adjust settings and re-run than to redo downstream work.

Keep the original file

Margin changes create a new document — keep the source PDF so you can try different values later.

Frequently asked questions

Clear answers to common questions about page margins and formatting.

Is my PDF uploaded to an external server?

No. All PDF processing takes place entirely within your browser using client-side JavaScript. Your file data is not sent to an external server.

What is the difference between Expand Page Size and Keep Page Size?

Expand Page Size increases the physical dimensions of the page by adding empty margins around the existing content. Keep Page Size maintains the original page dimensions by scaling down the content proportionally to fit within your specified margins.

Can I apply different margins to specific pages?

Yes. You can select Page Range and enter specific pages (e.g., 1-5, 8, 10-12) to apply margins only to selected parts of the document.

What happens if the margin values are too large?

In Keep Page Size mode, entering margins that exceed the width or height of the page will trigger an alert asking you to lower the values, preventing invalid blank or broken pages.

Does this tool work on mobile devices and tablets?

Yes. The tool runs in any modern browser on desktop computers, tablets, and mobile devices.

How it works

How this PDF margin tool was built

Because unit conversion, the expand/scale math, and mirroring all run client-side, I wrote up the implementation — how pdf-lib repositions embedded pages, and the arithmetic behind Mirror Margins.

Published on freeCodeCamp

How to Build a Browser-Based PDF Margin Tool Using JavaScript

Covers page-dimension math, unit conversion between mm/inch/px, and client-side PDF manipulation with pdf-lib.

Read the write-up on freeCodeCamp

Written by Bhavin Sheth · Founder, AllInOneTools