ASPX to PDF: How to Convert an ASPX file to PDF with IronPDF?

In this tutorial, we explore converting ASPX pages to PDF documents using the IronPDF library in an ASP.NET WebForms application. The process begins by setting up a new project in Visual Studio, filtering project types for ASP.NET WebApplication .NET Framework, and selecting Web Forms. After creating the project, we install IronPDF via NuGet packages, accepting the license agreement. Accessing IronPDF's namespace allows us to call the 'render this page as PDF' function, specifying that the file should be downloaded.

Running the application prompts a save dialog in the browser, rendering the ASPX page as a PDF document. We further customize the output by adding a simple footer, using PDF print options to set text alignment, font family, and size. The tutorial concludes with information on licensing and trial options, inviting users to explore more content on the Iron Software YouTube channel and website.

Below is an example code snippet demonstrating how to convert an ASPX page to a PDF using IronPDF:

using IronPdf;
using System;
using System.Web.UI;

namespace YourNamespace
{
    public partial class YourPage : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Create a new instance of the HtmlToPdf class from IronPDF
            var renderer = new HtmlToPdf();

            // Render the current page to a PDF document
            // The RenderUrlAsPdf function converts the specified URL to a PDF
            var pdfDocument = renderer.RenderUrlAsPdf(Request.Url.AbsoluteUri);

            // Customize the PDF by adding a footer with desired text and styling
            pdfDocument.Footer = new SimpleHeaderFooter()
            {
                CenterText = "Page footer text",
                DrawDividerLine = true,
                FontSize = 10
            };

            // Specify that the PDF should be sent to the client as a download
            pdfDocument.SaveAs(Response, "YourPage.pdf");
        }
    }
}
using IronPdf;
using System;
using System.Web.UI;

namespace YourNamespace
{
    public partial class YourPage : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Create a new instance of the HtmlToPdf class from IronPDF
            var renderer = new HtmlToPdf();

            // Render the current page to a PDF document
            // The RenderUrlAsPdf function converts the specified URL to a PDF
            var pdfDocument = renderer.RenderUrlAsPdf(Request.Url.AbsoluteUri);

            // Customize the PDF by adding a footer with desired text and styling
            pdfDocument.Footer = new SimpleHeaderFooter()
            {
                CenterText = "Page footer text",
                DrawDividerLine = true,
                FontSize = 10
            };

            // Specify that the PDF should be sent to the client as a download
            pdfDocument.SaveAs(Response, "YourPage.pdf");
        }
    }
}
Imports IronPdf
Imports System
Imports System.Web.UI

Namespace YourNamespace
	Partial Public Class YourPage
		Inherits Page

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			' Create a new instance of the HtmlToPdf class from IronPDF
			Dim renderer = New HtmlToPdf()

			' Render the current page to a PDF document
			' The RenderUrlAsPdf function converts the specified URL to a PDF
			Dim pdfDocument = renderer.RenderUrlAsPdf(Request.Url.AbsoluteUri)

			' Customize the PDF by adding a footer with desired text and styling
			pdfDocument.Footer = New SimpleHeaderFooter() With {
				.CenterText = "Page footer text",
				.DrawDividerLine = True,
				.FontSize = 10
			}

			' Specify that the PDF should be sent to the client as a download
			pdfDocument.SaveAs(Response, "YourPage.pdf")
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

Further Reading: ASPX Pages to PDF in ASP.NET

  • Comments: This code initializes the HtmlToPdf class provided by IronPDF to render the current ASPX page URL into a PDF format. The pdfDocument.Footer property allows adding simple styled footer text. The SaveAs method on the PDF document sends the file to the client for download.
Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.
< PREVIOUS
How to Generate PDFs with Async and Multithreading
NEXT >
How to Convert HTML to PDF in an ASP.NET MVC View