IronSoftware
  • Products
    Create, read, and edit PDFs Image to text in 127 languages Read and write QR & Barcodes No Office Interop required Extract structured data from websites 5 for the Price of 2 All 5 .NET product licenses from $998 Save 60% with Iron Suite Iron Suites - Donate $50
  • About Us
  • Contact Us

205 N. Michigan Ave. Chicago, IL 60611, USA +1 (312) 500-3060

  • Home
  • Licensing
  • EULA
  • Support & Update Extensions
  • Get Started
  • Features
  • Code Examples
  • Tutorials
  • FAQ
  • Troubleshooting
  • API Reference
  • Search
  • Free NuGet Download
IronPDF Library for C# IronPDF Library for C#
  • Home
  • Licensing
    • Licensing
    • EULA
    • Support & Update Extensions
  • Docs
    • Search
    • Get Started
    • Features
    • Code Examples
    • Tutorials
    • FAQ
    • Troubleshooting
    • API Reference
    • Search
  • Search
  • Free NuGet Download Total downloads: 3,793,736
Message's icon
IronPDF
Code Examples
  1. IronPDF
  2. Code Examples
  3. Set Custom Margins in PDF
IronPDF
Free for development from NuGet

Install with NuGet nuget.org/packages/IronPdf

PM > Install-Package IronPdf

Explore the Docs

  • Get Started
  • Features
  • Code Examples
    • HTML to PDF
    • Pixel Perfect HTML Formatting
    • ASPX to PDF
    • VB.Net PDF
    • .NET Core
    • Compatibility
      • Install & Deploy IronPDF
      • License Keys
      • Setup on macOS
      • Setup on Docker
      • Setup on Linux
      • Setup on Azure
      • Setup on AWS
      • Platform Specific Nuget Packages
    • Generating PDFs
      • Render ASP.NET and MVC to PDF
      • Render Razor Views to PDF
      • Convert XML to PDF
      • Generate PDF Reports
      • Work with PDF Images and CSS
      • Async & Threads to Generate PDFs
      • Render PDFs Behind System Logins
      • Chrome PDF Rendering Engine
    • Formatting PDFs
      • Create PDFs with Responsive CSS & Bootstrap
      • Render JavaScript in .NET PDFs
      • Use SVG Graphics
      • Support International Languages
      • Accessible PDFs & Section 508
      • Export PDF/A Format Docs in C#
      • Use WebFonts and Icons
      • Add Page Breaks
      • Encode UTF-8 and HTML Characters
      • Embed Images with DataURIs
      • Embed Images from Azure Blob Storage
    • Manipulating PDFs
      • Save & Export PDF Documents
      • Load & Export PDFs to Memory
      • Rotate Text and Pages
      • Sign PDFs Programmatically
      • Print PDFs Programmatically
      • View PDFs in a .NET Application
      • Read PDF Documents in C#
      • Parse PDFs in C#
      • Add Cover Page to PDF
      • Flatten PDF Images
      • Add Stamp to PDFs in C#
      • Split Multipage PDF
      • Add PDF Outlines and Bookmarks
    • Contacting Technical Support
      • How to Make an Engineering Support Request for IronPDF
      • Getting the Best Support for IronPDF
    • Common Questions
      • Azure Log Files
      • Red Hat Enterprise Linux (RHEL) support
      • Quick IronPDF Troubleshooting
      • Large Output Files Using ImageToPDF
      • Memory Leak in IronPDF
      • Fonts
      • IronPDF Chrome Renderer
      • Convert PDF to Base64
      • Render Delay & Timeout
      • Log4j
      • Pixel Perfect HTML Formatting
      • IronPDF Performance Assistance
      • AWS Lambda / Amazon Linux 2
      • Azure Plans and Tiers
      • Bootstrap / Flex / CSS
      • Initial render slow
      • AWS Log Files
      • What version of IronPDF should I use?
      • Font Kerning
      • Oversized DLL
    • Troubleshooting Guides
      • Adding IronPDF to a software program installer
      • Apply a license key in IronPDF
      • Azure Blob Storage
      • Blazor Server
      • Digital Signatures
      • International Languages and CMJK
      • IronPDF - System.Drawing.Common in .NET6
      • IronPdf and IIS
      • Kerberos
      • MetaData Visibility
      • Multi-Page Table Headers
      • PDF Viewer
      • Print From Network Printer
      • Rasterize to Image using MemoryStream
      • Render view to string
      • Visual C++ Redistributable for Visual Studio
    • Exception Messages
      • Access to the path 'Global-IronSoftwareDeploymentGlobal' is denied
      • Debugging Azure Functions Project on Local Machine
      • Error while deploying Chrome dependencies
      • Error while deploying Pdfium dependencies
      • Failed to deploy NuGet package
      • Invalid CefExecuteProcess return code of 0
      • IronCefSubprocess
      • IronPdf can not open / parse a specific PDF fIle
      • IronPDF Native Exception
      • IronPdfAssemblyVersionMismatchException
      • Network service crashed, restarting service
      • No function was found with the name SetLogEvent with error code (127)
      • Registry is not supported on this platform
      • Timeout while rendering PDF
      • Unhandled case for AdaptiveRenderEngine
      • Windows Nano Server / Servercore in .Net6 do not support System.Drawing
    • Product Release Notes
      • IronPDF v2022.5.5629
      • IronPDF v2022.5.5596
      • IronPDF v2022.4.5575
      • IronPDF v2022.4.5455
      • IronPDF v2022.3.5084
      • IronPDF v2022.2.4887
      • IronPDF v2022.1.4599
      • IronPDF v2021.12.4495
      • IronPDF v2021.12.4401
      • IronPDF v2021.11.4257
      • PDF.Core
      • IronPDF v2022.6.6115
  • API Reference
HTML to PDF HTML Files to PDF URL to a PDF Rendering Settings for Html to PDF ASPX Pages to PDF ASPX To PDF Settings Images To PDF TIFF to PDF with Multi-Page Support Async PDF Generation MultiThreaded PDF Generation Parallel PDF Generation Javascript in Html To Pdf Angular.JS to PDF Rendering Charts and Graphs in PDFs Custom Fonts in HTML to PDF Add Barcodes in HTML to PDF Set Temp PDF File Path Embedding Bitmaps and Images Website & System Logins
Add Classic Text Headers & Footers Add HTML Headers & Footers Add Headers/Footers on Specific Pages Page Numbers and Page Breaks Attach a Cover Page PDF Forms Responsive HTML to PDF Unicode & UTF-8 Support Backgrounds & Foregrounds Custom PDF Size Portrait & Landscape Orientation Set Custom Margins Set to Grayscale
Passwords, Security and MetaData Editing PDFs Joining 2 or more PDFs Rasterize a PDF to Images Split a PDF and Extract Pages Copying Pages between PDF Files Remove Specific PDF Pages Outlines & Bookmarks Annotations Digital Signatures PDF Encryption & Decryption Stamping New Content Adding HTML Content Efficiently Watermarking Read PDF Files in C# Paper Printing PDFs Text Find and Replace Add Attachments

Set Custom Margins

// PM> Install-Package IronPdf

using IronPdf;

var Renderer = new IronPdf.ChromePdfRenderer();

// Set Margins (in millimeters)
Renderer.RenderingOptions.MarginTop = 40;
Renderer.RenderingOptions.MarginLeft = 20;
Renderer.RenderingOptions.MarginRight = 20;
Renderer.RenderingOptions.MarginBottom = 40;

Renderer.RenderHTMLFileAsPdf("my-content.html").SaveAs("my-content.pdf");
' PM> Install-Package IronPdf

Imports IronPdf

Private Renderer = New IronPdf.ChromePdfRenderer()

' Set Margins (in millimeters)
Renderer.RenderingOptions.MarginTop = 40
Renderer.RenderingOptions.MarginLeft = 20
Renderer.RenderingOptions.MarginRight = 20
Renderer.RenderingOptions.MarginBottom = 40

Renderer.RenderHTMLFileAsPdf("my-content.html").SaveAs("my-content.pdf")
Read more
Install-Package IronPdf

Set Custom Margins

IronPDF allows you to edit margins to any value using RenderingOptions.
Previous Example
Next Example

Ready to get started? Version: 2022.7 just released

Free NuGet Download Total downloads: 3,793,736 View Licenses >
Try IronPDF for Free
Get Set Up in 5 Minutes
C# Nuget Library for PDF
Install with NuGet
Version: 2022.7
Install-Package IronPdf
nuget.org/packages/IronPdf/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronPdf"
  3. Select the package and install
C# PDF DLL
Download DLL
Version: 2022.7
Download Now
Manually install into your project
  1. Download and unzip IronPDF to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronPdf.dll"
Licenses from $499

Have a question? Get in touch with our development team.

Now that you’ve downloaded IronPDF
Want to deploy IronPDF to a live project for FREE?
Not ready to buy?

Want to deploy IronPDF to a live project for FREE?

What’s included?
30 days of fully-functional product
Test and share in a live environment
No watermarks in production
Get your free 30-day Trial Key instantly.
Thank you.
If you'd like to speak to our licensing team:
Schedule a call
Have a question? Get in touch with our development team.
No credit card or account creation required
Your Trial License Key has been emailed to you.
Not ready to buy?
Thank you.
View your license options:
Thank you.
If you'd like to speak to our licensing team:
View License
Schedule a call
Have a question? Get in touch with our development team.
Have a question? Get in touch with our development team.
Want to deploy IronPDF to a live project for FREE?
Not ready to buy?

Want to deploy IronPDF to a live project for FREE?

What’s included?
30 days of fully-functional product
Test and share in a live environment
No watermarks in production
Get your free 30-day Trial Key instantly.
Thank you.
If you'd like to speak to our licensing team:
Schedule a call
Have a question? Get in touch with our development team.
No credit card or account creation required
Your Trial License Key has been emailed to you.
Not ready to buy?
Download IronPDF free to apply
your Trial Licenses Key
Thank you.
If you'd like to speak to our licensing team:
Install with NuGet View Licenses
Schedule a call
Licenses from $499. Have a question? Get in touch.
Have a question? Get in touch with our development team.
Free 30-Day Trial Key

Fully-functional product, get the key instantly

IronPDF for .NET

When you need your PDF to look like HTML, fast.

Search

Documentation

  • Code Examples
  • API Reference
  • FAQ
  • Features
  • Blog
  • Credits
  • Product Brochure

Tutorials

  • Get Started
  • HTML to PDF
  • ASPX to PDF
  • VB.NET to PDF

Licensing

  • Buy a License
  • Support Extensions
  • Resellers
  • License Keys
  • EULA

Try IronPDF Free

  • Download on NuGet
  • Download DLL
  • 30-Day Trial License

When you need your PDF to look like HTML, fast.

Tesseract 5 OCR in the languages you need, We support 127+.

When you need to read, write, and style, QR & Barcodes, fast.

The Excel API you need, without the Office Interop hassle.

The power you need to scrape & output clean, structured data.

The complete .NET Suite for your office.

  • IRONSUITE
  • |
  • IRONPDF
  • IRONOCR
  • IRONBARCODE
  • IRONXL
  • IRONWEBSCRAPER
IronSoftware
205 N. Michigan Ave. Chicago, IL 60611 USA +1 (312) 500-3060
  • About Us
  • Contact Us

Supporting Teamseas

Copyright © Iron Software LLC 2013-2022

  • Terms
  • Privacy

Thank you!

Your license key has been delivered to the email provided. Contact us

48-Hour Upgrade Offer:

Save 50% on a
Professional Upgrade

Go Professional to cover 10 developers
and unlimited projects.

Upgrade to Professional

Upgrade

Professional

$600 USD

$299 USD


  • 10 developers
  • 10 locations
  • 10 projects