URL to a PDF

IronPDF makes it very straightforward to render HTML from existing URLs as PDF documents. There is a very high level of support for JavaScript, images, forms, and CSS.

Rendering PDFs from ASP.NET URLs that accept query string variables can facilitate smooth PDF development as a collaborative effort between designers and coders.


// C# Example: Converting a URL to a PDF using IronPDF // Import the IronPDF library using IronPdf; public class PdfGenerator { public static void ConvertUrlToPdf(string url, string outputPath) { // Create a new instance of HtmlToPdf to handle the conversion var Renderer = new HtmlToPdf(); // Render the URL into a PDF and save it to the specified path // The RenderUrlAsPdf method accepts a URL (website) you wish to convert PdfDocument pdf = Renderer.RenderUrlAsPdf(url); // Export the created PDF document to a file pdf.SaveAs(outputPath); // Inform the user the PDF has been created Console.WriteLine("PDF has been successfully generated at: " + outputPath); } }
// C# Example: Converting a URL to a PDF using IronPDF // Import the IronPDF library using IronPdf; public class PdfGenerator { public static void ConvertUrlToPdf(string url, string outputPath) { // Create a new instance of HtmlToPdf to handle the conversion var Renderer = new HtmlToPdf(); // Render the URL into a PDF and save it to the specified path // The RenderUrlAsPdf method accepts a URL (website) you wish to convert PdfDocument pdf = Renderer.RenderUrlAsPdf(url); // Export the created PDF document to a file pdf.SaveAs(outputPath); // Inform the user the PDF has been created Console.WriteLine("PDF has been successfully generated at: " + outputPath); } }
' C# Example: Converting a URL to a PDF using IronPDF ' Import the IronPDF library Imports IronPdf Public Class PdfGenerator	Public Shared Sub ConvertUrlToPdf(ByVal url As String, ByVal outputPath As String)	' Create a new instance of HtmlToPdf to handle the conversion	Dim Renderer = New HtmlToPdf()	' Render the URL into a PDF and save it to the specified path	' The RenderUrlAsPdf method accepts a URL (website) you wish to convert	Dim pdf As PdfDocument = Renderer.RenderUrlAsPdf(url)	' Export the created PDF document to a file	pdf.SaveAs(outputPath)	' Inform the user the PDF has been created	Console.WriteLine("PDF has been successfully generated at: " & outputPath)	End Sub End Class
$vbLabelText   $csharpLabel

Explanation:

  • Importing Library: The code begins by importing the IronPdf library, which provides the functionality to create PDFs from URLs.
  • PdfGenerator Class: Contains the ConvertUrlToPdf method, which handles the conversion process.
  • HtmlToPdf Instance: An instance of HtmlToPdf is created to access the methods required for rendering web pages into PDFs.
  • Render URL: The RenderUrlAsPdf method is called with the URL of the web page to convert it into a PdfDocument.
  • Saving PDF: The generated PDF is saved to the desired location using the SaveAs method.
  • Completion Message: A message is printed to the console to confirm successful PDF creation.

Make sure to have the IronPDF library installed in your project. You can easily do this via NuGet Package Manager by searching for "IronPDF".