How to Render URL to PDF in C# with IronPDF
IronPDF enables C# developers to convert any URL to PDF with one line of code, using the ChromePdfRenderer class to render web pages with full support for JavaScript, CSS, and images.
The library leverages a Chrome rendering engine to ensure accurate PDF representation of web pages, including dynamic content from JavaScript frameworks like Angular, React, and Vue.js.
Use IronPDF to build web scrapers, generate reports from live data, or create archives of web content. For developers seeking a comprehensive HTML to PDF solution, IronPDF offers extensive capabilities beyond URL conversion.
Quickstart: Convert a Web Page to PDF using IronPDF
This guide demonstrates how to use the ChromePdfRenderer class to convert URLs into PDFs with minimal code.
Get started making PDFs with NuGet now:
Install IronPDF with NuGet Package Manager
Copy and run this code snippet.
new IronPdf.ChromePdfRenderer().RenderUrlAsPdf("https://example.com").SaveAs("example.pdf");Deploy to test on your live environment
Minimal Workflow (5 steps)

- Download IronPDF C# Library from NuGet
- Instantiate the
ChromePdfRendererclass - Learn How to Render PDFs from URLs
- Modify the
RenderingOptionsto add header and footer - Check the PDF Output Document
How Do I Convert a URL to PDF with IronPDF?
This example shows IronPDF rendering a Wikipedia webpage into PDF using the RenderUrlAsPdf() method. This method requires an absolute URI pointing to the HTML document.
:path=/static-assets/pdf/content-code-examples/how-to/url-to-pdf.csusing IronPdf;
// Instantiate Renderer
var renderer = new ChromePdfRenderer();
// Create a PDF from a URL or local file path
var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/Main_Page");
// Export to a file or Stream
pdf.SaveAs("url.pdf");The RenderUrlAsPdf method supports HTTP and HTTPS protocols. Before continuing, complete the Installation Overview to set up IronPDF in your development environment.
For complex scenarios, explore additional URL to PDF examples that demonstrate authentication, custom headers, and rendering options.
What Does the Generated PDF Look Like?
This is the file that the code produced:
Advanced Configuration with RenderingOptions
Customize your PDF conversion through the RenderingOptions property. Configure page margins, paper size, orientation, and more.
using IronPdf;
// Advanced renderer with custom options
var renderer = new ChromePdfRenderer();
// Configure rendering options
renderer.RenderingOptions.MarginTop = 40;
renderer.RenderingOptions.MarginBottom = 40;
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
// Set custom paper size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait;
// Render URL to PDF with custom settings
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("customized-output.pdf");using IronPdf;
// Advanced renderer with custom options
var renderer = new ChromePdfRenderer();
// Configure rendering options
renderer.RenderingOptions.MarginTop = 40;
renderer.RenderingOptions.MarginBottom = 40;
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
renderer.RenderingOptions.CreatePdfFormsFromHtml = true;
// Set custom paper size
renderer.RenderingOptions.PaperSize = IronPdf.Rendering.PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = IronPdf.Rendering.PdfPaperOrientation.Portrait;
// Render URL to PDF with custom settings
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("customized-output.pdf");Handling JavaScript and Dynamic Content
Modern web pages rely on JavaScript to render content. IronPDF's Chrome rendering engine captures dynamic content through JavaScript rendering capabilities.
using IronPdf;
var renderer = new ChromePdfRenderer();
// Wait for JavaScript to execute
renderer.RenderingOptions.WaitFor.RenderDelay(2000); // Wait 2 seconds
// Or wait for specific JavaScript events
renderer.RenderingOptions.WaitFor.JavaScript(1500); // Maximum wait time
renderer.RenderingOptions.WaitFor.HtmlElement("div.dynamic-content", 5000);
var pdf = renderer.RenderUrlAsPdf("https://example.com/dynamic-page");
pdf.SaveAs("dynamic-content.pdf");using IronPdf;
var renderer = new ChromePdfRenderer();
// Wait for JavaScript to execute
renderer.RenderingOptions.WaitFor.RenderDelay(2000); // Wait 2 seconds
// Or wait for specific JavaScript events
renderer.RenderingOptions.WaitFor.JavaScript(1500); // Maximum wait time
renderer.RenderingOptions.WaitFor.HtmlElement("div.dynamic-content", 5000);
var pdf = renderer.RenderUrlAsPdf("https://example.com/dynamic-page");
pdf.SaveAs("dynamic-content.pdf");Adding Headers and Footers
Add headers and footers with page numbers, dates, or company information using IronPDF's Headers and Footers functionality.
using IronPdf;
var renderer = new ChromePdfRenderer();
// Add header with dynamic content
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
Height = 30,
HtmlFragment = "<div style='text-align:center;font-size:12px;'>{page} of {total-pages}</div>",
DrawDividerLine = true
};
// Add footer with company info
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
Height = 25,
HtmlFragment = "<div style='text-align:center;font-size:10px;'>© 2024 Your Company Name</div>",
DrawDividerLine = true
};
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("with-headers-footers.pdf");using IronPdf;
var renderer = new ChromePdfRenderer();
// Add header with dynamic content
renderer.RenderingOptions.HtmlHeader = new HtmlHeaderFooter()
{
Height = 30,
HtmlFragment = "<div style='text-align:center;font-size:12px;'>{page} of {total-pages}</div>",
DrawDividerLine = true
};
// Add footer with company info
renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter()
{
Height = 25,
HtmlFragment = "<div style='text-align:center;font-size:10px;'>© 2024 Your Company Name</div>",
DrawDividerLine = true
};
var pdf = renderer.RenderUrlAsPdf("https://example.com");
pdf.SaveAs("with-headers-footers.pdf");Optimizing CSS for PDF Output
IronPDF supports both screen and print CSS media types. Understanding how CSS media types affect output helps optimize PDF appearance. Learn more about CSS handling for PDF conversion to ensure professional-looking documents.
Common Use Cases
URL to PDF conversion serves these business scenarios:
- Report Generation: Convert dashboard URLs to PDF reports
- Web Archiving: Create PDF snapshots for compliance or documentation
- Invoice Generation: Convert web-based invoices to PDF format
- Content Publishing: Transform articles into downloadable PDFs
- Legal Documentation: Archive web content for legal proceedings
Best Practices and Performance Tips
Consider these best practices when converting URLs to PDF:
- Error Handling: Wrap conversion code in try-catch blocks to handle network issues
- Timeout Settings: Configure timeouts for slow-loading pages
- Resource Management: Use
usingstatements for proper disposal - Batch Processing: Consider parallel processing for multiple URLs
For comprehensive guidance, explore the complete URL to PDF documentation covering additional scenarios and troubleshooting.
Conclusion
IronPDF offers a reliable solution for converting URLs to PDFs in C#. With its Chrome rendering engine, customization options, and JavaScript support, it handles simple web pages to complex dynamic applications. Build enterprise reporting systems or web scrapers with IronPDF's URL to PDF capabilities.
Frequently Asked Questions
How do I convert a URL to PDF in C#?
You can convert a URL to PDF in C# using IronPDF's ChromePdfRenderer class with just one line of code: new IronPdf.ChromePdfRenderer().RenderUrlAsPdf("https://example.com").SaveAs("example.pdf"). This method renders web pages with full support for JavaScript, CSS, and images.
Does the URL to PDF conversion support JavaScript content?
Yes, IronPDF uses a Chrome rendering engine that fully supports JavaScript execution, including dynamic content from modern frameworks like Angular, React, and Vue.js. This ensures accurate PDF representation of interactive web pages.
What protocols are supported for URL to PDF conversion?
IronPDF's RenderUrlAsPdf method supports both HTTP and HTTPS protocols. The method requires an absolute URI pointing to the HTML document you want to convert.
Can I customize the PDF output when converting from URL?
Yes, IronPDF provides extensive customization through the RenderingOptions property. You can configure page margins, paper size, orientation, CSS media type, background printing, and form creation settings to tailor the PDF output to your needs.
What are some practical use cases for URL to PDF conversion?
IronPDF can be used to build web scrapers, generate reports from live data, or create archives of web content. The library's ability to render dynamic content makes it ideal for capturing complete web pages as they appear in a browser.






