Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Set EvoPDF margins through PdfDocumentOptions: LeftMargin, RightMargin, TopMargin, and BottomMargin. EvoPDF documents these values in points (1/72 inch), and each defaults to zero. However, an HTML @page margin rule takes precedence over the code values. Remove or change that CSS rule when you want the converter settings to control the PDF.

Set the four margins in EvoPDF

The converter exposes page options through its PdfDocumentOptions object. Set each side independently before converting the HTML:

var options = converter.PdfDocumentOptions;

options.LeftMargin = 36;
options.RightMargin = 36;
options.TopMargin = 48;
options.BottomMargin = 48;

The numbers above are illustrative settings, not EvoPDF recommendations. The documented unit is the typographic point: 72 points equal one inch. EvoPDF’s documentation says the four margin properties are zero by default, so content can reach the page edge unless you specify otherwise. The relevant properties and units are documented in EvoPDF’s HTML-to-PDF .NET Core guide.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Complete illustrative C# flow

The exact converter constructor and conversion method vary between EvoPDF editions. Adapt those calls to the package and version installed in your application; the margin assignments are the important part.

#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option
// Illustrative EvoPDF-style setup
var converter = new HtmlToPdfConverter();
var options = converter.PdfDocumentOptions;

options.LeftMargin = 36;   // 0.5 in
options.RightMargin = 36;  // 0.5 in
options.TopMargin = 48;    // 0.667 in
options.BottomMargin = 48; // 0.667 in

byte[] pdfBytes = converter.ConvertHtml("<html><body>Report</body></html>");
File.WriteAllBytes("report.pdf", pdfBytes);

This sample is intentionally labeled illustrative: the supplied EvoPDF references cover separate editions and do not establish that one constructor and conversion call compile unchanged in every release.

CSS @page can override your code

If the PDF ignores the values assigned in C#, inspect the HTML and its stylesheets before changing the numbers. A page rule such as this has priority over EvoPDF’s code-level margins:

@page {
  margin: 2cm;
}

To let PdfDocumentOptions own the margins, remove the declaration or revise the stylesheet so it does not set a competing page margin. To let CSS own the layout, put the intended values in @page and treat the code properties as secondary. EvoPDF documents this precedence in HTML to PDF Page Setup and Scaling.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Code versus CSS: which should own the layout?

Approach Owner Scope Best fit
EvoPDF options Application configuration Every conversion using that converter instance Centralized templates, tenant-specific settings, or a single PDF policy
CSS @page HTML document stylesheet The page rules in that document Self-contained print templates and designs maintained with the HTML

Choose one clear owner where possible. Keeping both declarations usually creates confusing precedence, especially when a shared print stylesheet is loaded by several templates.

Top and bottom margins with headers and footers

Check AutoResizePdfMargins when only the top or bottom behaves unexpectedly. With automatic resizing enabled, EvoPDF uses the documented header and footer heights to set those margins, replacing the corresponding code values. Disable automatic resizing when your explicit top and bottom settings must remain in force.

When automatic resizing is disabled, reserve enough space inside the top and bottom margins for the header and footer. A header that is taller than the available top margin can overlap body content or force an unexpected layout. The behavior and option are described in the EvoPDF Next page-setup documentation.

A predictable header/footer checklist

  • Decide whether EvoPDF or your CSS should own page margins.
  • Inspect whether AutoResizePdfMargins is enabled.
  • If it is enabled, measure the configured header and footer heights and expect those values to determine the top and bottom margins.
  • If it is disabled, set explicit top and bottom values large enough to contain the header and footer.
  • Render a page containing the longest header, footer, and a page break; do not validate only a short first page.

Print media, page size, and orientation

Margins are only one part of page geometry. EvoPDF’s Next .NET guide states that the default CSS media type is screen. Set the converter’s MediaType to print when the document’s print stylesheet should apply, then inspect its print rules for an @page margin.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Also distinguish margins from page size, orientation, layout method, and CSS page-size preferences. A correct margin can still appear wrong if the page is the wrong size, landscape mode is active, or the layout uses a different page-size rule. Establish the intended paper size and orientation first, then resolve margin ownership.

Example print CSS

@media print {
  body { margin: 0; }
}

@page {
  size: A4 portrait;
  margin: 18mm 15mm 20mm 15mm;
}

In this example, the four @page values are top, right, bottom, and left. They override the matching EvoPDF code properties. If you want code-controlled margins instead, remove the margin declaration while retaining any page-size rule you still need.

Converting units safely

EvoPDF expects points, while CSS commonly uses millimeters, centimeters, or inches. Convert deliberately rather than assuming the units match:

  • 1 inch = 72 points.
  • 1 centimeter is approximately 28.346 points.
  • 1 millimeter is approximately 2.835 points.

For example, a 12.7 mm (0.5 inch) margin is 36 points. CSS values remain in CSS units when declared in @page; only values assigned to the EvoPDF properties need conversion to points.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why EvoPDF margins appear to be ignored

An @page rule wins

Symptom: changing LeftMargin or another property has no visible effect.

Fix: search every loaded stylesheet and inline style for @page and its margin declaration. Remove or edit the rule, or intentionally move the desired values into CSS.

Automatic margin resizing is active

Symptom: top or bottom margins match header/footer dimensions instead of your numbers.

Fix: disable AutoResizePdfMargins to keep explicit code values, then increase those values if the header or footer needs more room.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Print CSS is being applied unexpectedly

Symptom: the PDF differs from the browser preview, including page rules or hidden elements.

Fix: check the converter’s MediaType. EvoPDF documents screen as the default; use print only when you intend print media rules to participate.

The page geometry is wrong

Symptom: margins seem proportionally correct but the content wraps too early or too late.

Fix: verify paper size, orientation, layout method, and any CSS size declaration before adjusting margins.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Content is clipped or overlaps a footer

Symptom: the first or last lines collide with a header/footer.

Fix: reserve sufficient top and bottom space, test the longest header/footer, and check automatic resizing. Do not solve an overlap by changing only the left and right margins.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Reliable validation workflow

  1. Create a diagnostic HTML page with a visible border, a heading at the top, a footer-sized block, and enough text to produce multiple pages.
  2. Temporarily remove @page margin declarations so the code values are the only margin source.
  3. Set explicit point values on all four properties and render the PDF.
  4. Confirm left, right, top, and bottom distances independently; a symmetric-looking page can hide a wrong bottom value.
  5. Reintroduce the production stylesheet and render again. If the geometry changes, inspect its @page rules and print media settings.
  6. Test the actual paper size, orientation, headers, footers, long tables, images, and page breaks used by the application.

Or skip the browser setup

If your goal is to obtain a clean image or PDF of an HTML page rather than generate a PDF inside EvoPDF, ScreenshotNeo provides a single HTTP request. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its PDF options include paper size, margins, landscape mode, and page ranges.

cURL (see the ScreenshotNeo documentation):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. One thousand screenshots per month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Edition and version scope

The property names and precedence described here come from EvoPDF’s official Next .NET page-setup guide and its HTML-to-PDF .NET Core documentation. Those pages cover distinct editions, so verify the API surface against your installed package and release. EvoPDF’s converter options reference is available at HTML To PDF Converter Options.

Frequently Asked Questions

Can I use CSS millimeters for EvoPDF code margins?

CSS units apply to CSS declarations. Values assigned to EvoPDF’s four margin properties are documented in points, so convert millimeters or inches before assigning them.

Should I set margins in both CSS and C#?

Usually choose one owner. If an @page margin exists, EvoPDF documents that it overrides the code properties.

Why are only the top and bottom margins different?

Check AutoResizePdfMargins and the configured header and footer heights; automatic resizing can replace those two code values.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does EvoPDF use print styles by default?

The EvoPDF Next .NET guide documents screen as the default CSS media type. Set MediaType to print when print rules are intended.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.