Add Margin to PDF
Edit → Add Margin to PDF
The Add Margin to PDF API adds custom margins to any side of the PDF. You send the PDF (docContent, docName) and optional marginLeft, marginRight, marginTop, marginBottom (in millimeters, 0–100). The page size is adjusted to accommodate the margins. The API returns the PDF with the new margins. Use the tester below to try it; more details are in the sections that follow.
Try the Add Margin to PDF API
Endpoint: POST /api/v2/AddMargin · Required: api-key, docContent, docName
Use the form below to send your API key and PDF (Base64), and set left/right/top/bottom margins in mm. The response is the PDF with margins applied. No code required—fill the fields and click Send request.
Overview, parameters, and use cases
- Overview
- Parameters
- Use cases
What is Add Margin to PDF?
This endpoint adds custom margins to the left, right, top, and bottom of each page. Margins are in millimeters (0–100). The page size is changed to accommodate the margins, so content is not cropped—the effective printable area is reduced. Use it when you need consistent margins for binding, printing, or layout.
Key features
- Per-side margins – marginLeft, marginRight, marginTop, marginBottom in mm (0–100).
- Page size adjustment – The API adjusts page size so margins are added; content stays intact.
- Optional – Omit a margin to leave that side unchanged (or use 0).
Use when preparing PDFs for print (binding margins) or when you need a consistent gutter. Combine with Add Page Number to PDF or Add HTML Header Footer to PDF after setting margins so headers/footers sit in the margin area.
API parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| api-key | string | Yes | Your PDF4me API key, Base64 encoded. Get it from the dashboard. |
| docContent | base64 | Yes | PDF file content (Base64). |
| docName | string | Yes | Output PDF file name (e.g. output.pdf). |
| marginLeft, marginRight, marginTop, marginBottom | integer | No | Margins in millimeters (0–100). |
| async | boolean | No | Enable asynchronous processing. |
When to use Add Margin to PDF
- Print and binding – Add left/right margins for binding or hole punching.
- Layout consistency – Ensure all pages have the same margin before adding headers, footers, or page numbers.
- Conversion pipelines – Normalize margins after converting from Word or HTML so downstream tools get consistent layout.
For request/response schemas and code samples, see Add Margin to PDF in the PDF4me API docs.
Prerequisites
Before using this endpoint, make sure you have:
- A valid PDF4me API key (Get your API Key)
- A PDF document in Base64 format or a public URL to a PDF file
Response Format
The API returns a PDF document with the specified margins applied. The page size will be adjusted to accommodate the margins.