How to Use Virtual Viewport and Zoom in C#

How to use C# Virtual Viewport and Zoom in IronPDF

Control viewport and zoom in IronPDF by using the RenderingOptions property to set ViewPortWidth and Zoom values, or leverage preset PaperFit modes for automatic layout handling during HTML to PDF conversion.

In HTML to PDF rendering, the viewport determines how web page layouts are captured in the resulting PDF document. It represents the virtual screen size that the browser uses to render the web page. When working with IronPDF's Chrome rendering engine, understanding viewport settings is essential for achieving accurate results.

Zoom controls the scaling of web page content in the PDF document. Fine-tuning the zoom level adjusts the content size in the PDF, ensuring proper layout and formatting. This feature is particularly useful when handling responsive CSS layouts that must adapt to different page sizes.

Quickstart: Control Zoom and Viewport with IronPDF

Manage zoom and viewport settings in your HTML to PDF conversions using IronPDF. This guide provides a simple code snippet to start scaling HTML content. With minimal code, you can ensure PDFs render correctly while maintaining responsive design elements and desired layouts.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    new IronPdf.ChromePdfRenderer { RenderingOptions = { ViewPortWidth = 1280, Zoom = 1.8 } }
        .RenderUrlAsPdf("https://example.com")
        .SaveAs("zoomedViewport.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer


What Are the Paper Fit Modes in IronPDF?

Access the PaperFit field in RenderingOptions to use preset methods for specific rendering types and modes. These modes provide different approaches for rendering HTML content onto PDF pages, similar to techniques used when creating custom paper sizes. Let's examine each PaperFit mode by rendering the Wikipedia main page for comparison.

PaperFit modes handle various content layouts, from standard web pages to specialized documents like receipts or reports. Each mode optimizes for specific use cases, ensuring PDFs maintain the intended design and readability regardless of the source content's original format.

How Do I Use Chrome Default Rendering?

This mode lays out PDF pages as they appear in Google Chrome's print preview. It configures rendering options to match the appearance of a web page when printed from Chrome. The responsive CSS viewport interprets the specified paper size based on its width. Use the UseChromeDefaultRendering method to configure this.

Chrome default rendering maintains consistency with browser print expectations. It works well for standard web pages and documents where you want to preserve the natural content flow as it appears in typical browser print operations. For advanced scenarios involving JavaScript rendering, this mode ensures proper execution and display of dynamic content.

:path=/static-assets/pdf/content-code-examples/how-to/viewport-zoom-default-chrome.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Chrome default rendering
renderer.RenderingOptions.PaperFit.UseChromeDefaultRendering();

// Render web URL to PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

pdf.SaveAs("chromeDefault.pdf");
$vbLabelText   $csharpLabel

How Do I Use Responsive CSS Rendering?

In responsive CSS mode, specify a viewport width by passing a value to the UseResponsiveCssRendering method. The default ViewPortWidth is 1280 pixels. The viewport unit is pixel-based, representing a virtual browser viewport for responsive CSS designs. This mode handles modern frameworks and works with Bootstrap and Flex CSS layouts.

Responsive CSS defines HTML rendering based on the ViewPortWidth parameter, scaling content to fit the specified paper size width. This approach suits modern web applications using responsive design principles, ensuring PDFs maintain the intended layout regardless of original viewport size. When working with custom margins, this mode provides precise control over content adaptation to different page dimensions.

:path=/static-assets/pdf/content-code-examples/how-to/viewport-zoom-responsive-css.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Responsive CSS rendering
renderer.RenderingOptions.PaperFit.UseResponsiveCssRendering(1280);

// Render web URL to PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

pdf.SaveAs("responsiveCss.pdf");
$vbLabelText   $csharpLabel

How Do I Use Scaled Rendering?

The UseScaledRendering method mimics Chrome Print Preview behavior for a specified paper size while providing an adjustable zoom level. This method scales content according to the input zoom percentage.

Scaled rendering offers precise control over content appearance in PDFs. Unlike fixed viewport approaches, this method allows dynamic content size adjustment, making it ideal for documents requiring readability at different scales or when preparing PDFs for various display contexts. This technique complements page orientation and rotation settings for optimal document presentation.

:path=/static-assets/pdf/content-code-examples/how-to/viewport-zoom-scaled.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Scaled rendering
renderer.RenderingOptions.PaperFit.UseScaledRendering(180);

// Render web URL to PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

pdf.SaveAs("scaled.pdf");
$vbLabelText   $csharpLabel

How Do I Use Fit to Page Rendering?

Fit to page rendering scales content to fit the specified paper size. It measures the minimum HTML content width after rendering and scales it to fit one sheet of paper width where possible. The configurable minimum pixel width ensures correct display and responsiveness to CSS3 layout rules.

This mode handles content that might span multiple pages horizontally. It works well for wide tables, charts, or dashboards that must fit within a single page width. Automatic scaling ensures all content remains visible without horizontal scrolling, making it ideal for generating PDF reports where readability matters.

:path=/static-assets/pdf/content-code-examples/how-to/viewport-zoom-fit-to-page.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Fit to page rendering
renderer.RenderingOptions.PaperFit.UseFitToPageRendering();

// Render web URL to PDF
PdfDocument pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");

pdf.SaveAs("fitToPage.pdf");
$vbLabelText   $csharpLabel

How Do I Use Continuous Feed Rendering?

Continuous feed rendering creates a single-page PDF that fits all content onto one page, suitable for documents like consumer bills or receipts. The default PDF page width is 80.0 millimeters with 5-millimeter margins. Let's render the 'receipt.html' file to PDF.

Customize page width and margin using the width and margin parameters for flexibility. This mode creates concise, single-page documents. It generates receipts, invoices, or any document requiring continuous flow without page breaks. Combined with HTML to PDF page break control, you can create sophisticated document layouts for specific requirements.

:path=/static-assets/pdf/content-code-examples/how-to/viewport-zoom-continuous-feed.cs
using IronPdf;

ChromePdfRenderer renderer = new ChromePdfRenderer();

int width = 90;
int margin = 0;

// Continuous feed rendering
renderer.RenderingOptions.PaperFit.UseContinuousFeedRendering(width, margin);

// Render web URL to PDF
PdfDocument pdf = renderer.RenderHtmlFileAsPdf("receipt.html");

pdf.SaveAs("continuousFeed.pdf");
$vbLabelText   $csharpLabel

Ready to see what else you can do? Check out our tutorial page here: Convert PDFs

Frequently Asked Questions

What is viewport in HTML to PDF conversion?

In IronPDF, the viewport represents the virtual screen size that the Chrome rendering engine uses to render web pages before converting them to PDF. It determines how web page layouts are captured in the resulting PDF document, which is essential for achieving accurate rendering results.

How can I control zoom and viewport width in one line of code?

You can control both viewport width and zoom in IronPDF using a single line: new IronPdf.ChromePdfRenderer { RenderingOptions = { ViewPortWidth = 1280, Zoom = 1.8 } }.RenderUrlAsPdf('https://example.com').SaveAs('zoomedViewport.pdf'). This sets the viewport to 1280 pixels and applies a 1.8x zoom factor.

What are PaperFit modes?

PaperFit modes in IronPDF are preset methods accessed through the RenderingOptions.PaperFit field that provide different approaches for rendering HTML content onto PDF pages. Each mode optimizes for specific use cases like standard web pages, receipts, or reports, ensuring PDFs maintain the intended design and readability.

Why is zoom control important for responsive CSS layouts?

Zoom control in IronPDF is particularly useful when handling responsive CSS layouts that must adapt to different page sizes. Fine-tuning the zoom level adjusts the content size in the PDF, ensuring proper layout and formatting while maintaining responsive design elements.

What rendering engine does the viewport and zoom feature use?

The viewport and zoom features in IronPDF utilize the Chrome rendering engine. This ensures that web pages are rendered accurately and consistently, matching how they would appear in Google Chrome before being converted to PDF.

What is Chrome Default Rendering mode?

Chrome Default Rendering is a PaperFit mode in IronPDF that lays out PDF pages as they appear in Google Chrome's print preview. It configures rendering options to match the appearance of a web page when printed from Chrome, interpreting the responsive CSS viewport based on the specified paper size.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More
Ready to Get Started?
Nuget Downloads 17,012,929 | Version: 2025.12 just released