URL到PDF

从网页 URL 渲染为 PDF 就像将 URL 提供给fromUrl方法一样简单。 这将返回一个可以导出或进行进一步 PDF 文档增强的 PDF 对象。 有关使用 IronPDF 将网页转换为 PDF 的更多信息,请查看IronPDF HTML to PDF 转换指南

// Import necessary namespace
using IronPdf;

class Program
{
    static void Main()
    {
        // Define the URL of the web page you want to convert to a PDF
        var url = "https://example.com";

        // Create an instance of IronPdf.HtmlToPdf
        var renderer = new HtmlToPdf();

        // Render the URL to a PDF document
        // The fromUrl method takes the web page URL and returns a PdfDocument object
        PdfDocument pdf = renderer.RenderUrlAsPdf(url);

        // Export the PDF document to a file
        // Specify the file path where the PDF will be saved
        pdf.SaveAs("WebPageToPdf.pdf");

        // Output success message
        System.Console.WriteLine("Web page has been successfully converted to PDF.");
    }
}
// Import necessary namespace
using IronPdf;

class Program
{
    static void Main()
    {
        // Define the URL of the web page you want to convert to a PDF
        var url = "https://example.com";

        // Create an instance of IronPdf.HtmlToPdf
        var renderer = new HtmlToPdf();

        // Render the URL to a PDF document
        // The fromUrl method takes the web page URL and returns a PdfDocument object
        PdfDocument pdf = renderer.RenderUrlAsPdf(url);

        // Export the PDF document to a file
        // Specify the file path where the PDF will be saved
        pdf.SaveAs("WebPageToPdf.pdf");

        // Output success message
        System.Console.WriteLine("Web page has been successfully converted to PDF.");
    }
}
' Import necessary namespace
Imports IronPdf

Friend Class Program
	Shared Sub Main()
		' Define the URL of the web page you want to convert to a PDF
		Dim url = "https://example.com"

		' Create an instance of IronPdf.HtmlToPdf
		Dim renderer = New HtmlToPdf()

		' Render the URL to a PDF document
		' The fromUrl method takes the web page URL and returns a PdfDocument object
		Dim pdf As PdfDocument = renderer.RenderUrlAsPdf(url)

		' Export the PDF document to a file
		' Specify the file path where the PDF will be saved
		pdf.SaveAs("WebPageToPdf.pdf")

		' Output success message
		System.Console.WriteLine("Web page has been successfully converted to PDF.")
	End Sub
End Class
$vbLabelText   $csharpLabel

在我们的 HTML 到 PDF 转换指南中了解更多信息。

准备开始了吗?
版本: 2025.11 刚刚发布