跳過到頁腳內容
使用IRONPDF

如何在ASP.NET中使用C#和IronPDF查看PDF文件

大多數人使用專用的桌面應用程式在電腦上開啟PDF,但軟體工程師也可以使用IronPDF在C#中程式化地創建、查看、開啟、閱讀和編輯PDF內容。

IronPDF在ASP.NET和C#中讀取PDF檔案時證明是一個非常有用的插件。

您可以下載ASP.NET PDF演示專案

使用C#和IronPDF可以快速輕鬆地創建PDF文檔。

PDF文檔的設計和佈局大部分可以通過使用現有的HTML資產來完成,或者將該任務委託給網頁設計員工; 它負責將PDF生成整合到您的應用程式中這些耗時的任務,並自動將準備好的文檔轉換為PDF。 使用.NET,您可以:

  • 轉換網頁表單、本地HTML頁面和其他網站為PDF格式。
  • 允許用戶下載文檔,通過電子郵件與他人分享,或將其保存在雲端。
  • 向客戶開具發票並提供報價; 準備報告; 協商合同和其他文書工作。
  • 在.NET Framework和.NET Core中與ASP.NET、ASP.NET Core、Web Forms、MVC、Web APIs和其他程式語言一起工作。

設置IronPDF庫

有兩種方法來安裝該庫;

使用NuGet包管理器安裝

IronPDF可以通過Visual Studio插件或從命令行的NuGet包管理器安裝。在Visual Studio中瀏覽到控制台,然後輸入以下命令:

Install-Package IronPdf

直接從網站下載DLL文件

或者,您可以直接從網站獲取DLL。

記得在使用IronPDF的任何cs類文件頂部包含以下指令:

using IronPdf;
using IronPdf;
Imports IronPdf
$vbLabelText   $csharpLabel

查看<IronPDF的詳細功能概述

IronPDF是一個必備的插件。 立即獲得您的與IronPDF NuGet包一起嘗試

在.NET C#中從HTML字符串創建PDF文件

在C#中從HTML字符串創建PDF文件是一種創建新PDF文件的高效且有趣的方法。

ChromePdfRenderer中的RenderHtmlAsPdf函數提供了一種輕鬆的方法,將任何HTML(HTML5)字符串轉換為PDF文檔,這個得益於IronPDF DLL中嵌入的谷歌Chromium引擎版本。

// Create a renderer to convert HTML to PDF
var renderer = new ChromePdfRenderer();

// Convert an HTML string to a PDF
using var renderedPdf = renderer.RenderHtmlAsPdf("<h1>My First HTML to Pdf</h1>");

// Define the output path for the PDF
var outputPath = "My_First_Html.pdf";

// Save the rendered PDF to the specified path
renderedPdf.SaveAs(outputPath);

// Automatically open the newly created PDF
System.Diagnostics.Process.Start(outputPath);
// Create a renderer to convert HTML to PDF
var renderer = new ChromePdfRenderer();

// Convert an HTML string to a PDF
using var renderedPdf = renderer.RenderHtmlAsPdf("<h1>My First HTML to Pdf</h1>");

// Define the output path for the PDF
var outputPath = "My_First_Html.pdf";

// Save the rendered PDF to the specified path
renderedPdf.SaveAs(outputPath);

// Automatically open the newly created PDF
System.Diagnostics.Process.Start(outputPath);
' Create a renderer to convert HTML to PDF
Dim renderer = New ChromePdfRenderer()

' Convert an HTML string to a PDF
Dim renderedPdf = renderer.RenderHtmlAsPdf("<h1>My First HTML to Pdf</h1>")

' Define the output path for the PDF
Dim outputPath = "My_First_Html.pdf"

' Save the rendered PDF to the specified path
renderedPdf.SaveAs(outputPath)

' Automatically open the newly created PDF
System.Diagnostics.Process.Start(outputPath)
$vbLabelText   $csharpLabel

RenderHtmlAsPdf是一個強大的工具,可完全支持CSS、JavaScript和圖像。 如果這些資料存儲在硬碟上,則可能需要設置RenderHtmlAsPdf的第二個參數。

以下代碼將生成一個PDF文件:

// Render HTML to PDF with a base path for local assets
var renderPdf = renderer.RenderHtmlAsPdf("<img src='image_1.png'/>", @"C:\Newproject");
// Render HTML to PDF with a base path for local assets
var renderPdf = renderer.RenderHtmlAsPdf("<img src='image_1.png'/>", @"C:\Newproject");
' Render HTML to PDF with a base path for local assets
Dim renderPdf = renderer.RenderHtmlAsPdf("<img src='image_1.png'/>", "C:\Newproject")
$vbLabelText   $csharpLabel

所有引用的CSS樣式表、圖片和JavaScript文件將相對於BaseUrlPath,從而可以維持一個更有組織和合理的結構。 當然,您可以利用網絡上可以獲得的圖片、樣式表和資產,比如Web字體、Google字體以及甚至jQuery,如果您選擇的話。

使用現有HTML URL創建PDF文檔

現有的URLs可以使用C#高效地渲染為PDF; 這同樣允許團隊將PDF設計與後端PDF渲染工作分配到不同部門,這是有益的。

下面的代碼演示了如何從其URL渲染endeavorcreative.com頁面:

// Create a renderer for converting URLs to PDF
var renderer = new ChromePdfRenderer();

// Convert the specified URL to a PDF
using var renderedPdf = renderer.RenderUrlAsPdf("https://endeavorcreative.com/setting-up-wordpress-website-from-scratch/");

// Specify the output path for the PDF
var outputPath = "Url_pdf.pdf";

// Save the PDF to the specified path
renderedPdf.SaveAs(outputPath);

// Open the newly created PDF
System.Diagnostics.Process.Start(outputPath);
// Create a renderer for converting URLs to PDF
var renderer = new ChromePdfRenderer();

// Convert the specified URL to a PDF
using var renderedPdf = renderer.RenderUrlAsPdf("https://endeavorcreative.com/setting-up-wordpress-website-from-scratch/");

// Specify the output path for the PDF
var outputPath = "Url_pdf.pdf";

// Save the PDF to the specified path
renderedPdf.SaveAs(outputPath);

// Open the newly created PDF
System.Diagnostics.Process.Start(outputPath);
' Create a renderer for converting URLs to PDF
Dim renderer = New ChromePdfRenderer()

' Convert the specified URL to a PDF
Dim renderedPdf = renderer.RenderUrlAsPdf("https://endeavorcreative.com/setting-up-wordpress-website-from-scratch/")

' Specify the output path for the PDF
Dim outputPath = "Url_pdf.pdf"

' Save the PDF to the specified path
renderedPdf.SaveAs(outputPath)

' Open the newly created PDF
System.Diagnostics.Process.Start(outputPath)
$vbLabelText   $csharpLabel

結果是所有的超連結(HTML連結)甚至HTML表單都會在生成的PDF中保留。

從現有HTML文檔創建PDF文檔

這一部分展示如何渲染任何本地HTML文件。對所有相對資產,如CSS、圖片和JavaScript等,這看起來好像該文件是使用file:/協議開啟的。

// Create a renderer for existing HTML files
var renderer = new ChromePdfRenderer();

// Render an HTML file to PDF
using var renderedPdf = renderer.RenderHtmlFileAsPdf("Assets/test1.html");

// Specify the output path for the PDF
var outputPath = "test1_pdf.pdf";

// Save the PDF to the specified path
renderedPdf.SaveAs(outputPath);

// Open the newly created PDF
System.Diagnostics.Process.Start(outputPath);
// Create a renderer for existing HTML files
var renderer = new ChromePdfRenderer();

// Render an HTML file to PDF
using var renderedPdf = renderer.RenderHtmlFileAsPdf("Assets/test1.html");

// Specify the output path for the PDF
var outputPath = "test1_pdf.pdf";

// Save the PDF to the specified path
renderedPdf.SaveAs(outputPath);

// Open the newly created PDF
System.Diagnostics.Process.Start(outputPath);
' Create a renderer for existing HTML files
Dim renderer = New ChromePdfRenderer()

' Render an HTML file to PDF
Dim renderedPdf = renderer.RenderHtmlFileAsPdf("Assets/test1.html")

' Specify the output path for the PDF
Dim outputPath = "test1_pdf.pdf"

' Save the PDF to the specified path
renderedPdf.SaveAs(outputPath)

' Open the newly created PDF
System.Diagnostics.Process.Start(outputPath)
$vbLabelText   $csharpLabel

這種策略的優勢在於它允許開發人員在創建HTML內容時在瀏覽器中進行測試。 IronPDF的渲染引擎是基於Chrome網絡瀏覽器的。 因此,建議使用XML到PDF轉換,因為使用XSLT模板可以將XML內容打印到PDF。

將ASP.NET Web Forms轉換為PDF文件

僅需一行代碼,就可以將ASP.NET在線表單轉換為PDF格式,而不是HTML。 將代碼行放在頁面代碼後台文件的Page_Load方法中以使其顯示在頁面上。

ASP.NET Web Forms應用程式可以從頭創建也可以從以前的版本打開。

如果尚未安裝,請安裝NuGet包。

應使用using關鍵字來引入IronPdf命名空間。

導航到您想要轉換為PDF的頁面的代碼後台。 例如,使用ASP.NET的文件Default.aspx.cs

RenderThisPageAsPdfAspxToPdf類上的一個方法。

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

namespace WebApplication7
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Render the current page as a PDF in the browser
            AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.InBrowser);
        }
    }
}
using IronPdf;
using System;
using System.Web.UI;

namespace WebApplication7
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Render the current page as a PDF in the browser
            AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.InBrowser);
        }
    }
}
Imports IronPdf
Imports System
Imports System.Web.UI

Namespace WebApplication7
	Partial Public Class _Default
		Inherits Page

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			' Render the current page as a PDF in the browser
			AspxToPdf.RenderThisPageAsPdf(AspxToPdf.FileBehavior.InBrowser)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

這需要安裝IronPdf.Extensions.ASPX NuGet包。 因為ASPX已經被MVC模型取代了,所以在.NET Core中不可用。

應用HTML模板

對於內部網和網站開發人員,模板化或“批量生產”PDF的能力是標準的需求。

而不是為PDF文檔創建模板,IronPDF庫提供了一種通過利用現有的、經過良好測試的技術為HTML生成模板的方法。

當HTML模板補充了查詢字符串或資料庫中的數據時,會創建一個動態生成的PDF文件,如下所示。

舉個例子,考慮C#字符串類及其屬性。 Format方法在基本的“郵件合併”操作中運作得很好。

// Basic HTML String Formatting
string formattedString = String.Format("<h1>Hello {0}!</h1>", "World");
// Basic HTML String Formatting
string formattedString = String.Format("<h1>Hello {0}!</h1>", "World");
' Basic HTML String Formatting
Dim formattedString As String = String.Format("<h1>Hello {0}!</h1>", "World")
$vbLabelText   $csharpLabel

因為HTML文件可能相當龐大,常見的做法是使用任意的佔位符,例如[[NAME]]然後用實際數據替換它們。

以下示例將生成三個PDF文檔,每個文檔將為不同的用戶定制。

// Define an HTML template with a placeholder
var htmlTemplate = "<p>[[NAME]]</p>";

// Sample data to replace placeholders
var names = new[] { "John", "James", "Jenny" };

// Create a new PDF for each name
foreach (var name in names)
{
    // Replace placeholder with actual name
    var htmlInstance = htmlTemplate.Replace("[[NAME]]", name);

    // Create a renderer and render the HTML as PDF
    var renderer = new ChromePdfRenderer();
    using var pdf = renderer.RenderHtmlAsPdf(htmlInstance);

    // Save the PDF with the name in the filename
    pdf.SaveAs($"{name}.pdf");
}
// Define an HTML template with a placeholder
var htmlTemplate = "<p>[[NAME]]</p>";

// Sample data to replace placeholders
var names = new[] { "John", "James", "Jenny" };

// Create a new PDF for each name
foreach (var name in names)
{
    // Replace placeholder with actual name
    var htmlInstance = htmlTemplate.Replace("[[NAME]]", name);

    // Create a renderer and render the HTML as PDF
    var renderer = new ChromePdfRenderer();
    using var pdf = renderer.RenderHtmlAsPdf(htmlInstance);

    // Save the PDF with the name in the filename
    pdf.SaveAs($"{name}.pdf");
}
' Define an HTML template with a placeholder
Dim htmlTemplate = "<p>[[NAME]]</p>"

' Sample data to replace placeholders
Dim names = { "John", "James", "Jenny" }

' Create a new PDF for each name
For Each name In names
	' Replace placeholder with actual name
	Dim htmlInstance = htmlTemplate.Replace("[[NAME]]", name)

	' Create a renderer and render the HTML as PDF
	Dim renderer = New ChromePdfRenderer()
	Dim pdf = renderer.RenderHtmlAsPdf(htmlInstance)

	' Save the PDF with the name in the filename
	pdf.SaveAs($"{name}.pdf")
Next name
$vbLabelText   $csharpLabel

ASP.NET MVC路由:下載此頁面的PDF版本

使用ASP.NET MVC框架,您可以將用戶引導到一個PDF文件。

在建立新的ASP.NET MVC應用程式或向現有應用加入MVC控制器時選擇此選項。 通過從下拉菜單中選擇ASP.NET Web Application (.NET Framework) > MVC啟動Visual Studio新專案向導。 或者,您可以打開現有的MVC專案。 替換Controllers文件夾中HomeController文件中的Index方法,或在Controllers文件夾中創建一個新的控制器。

以下是程式碼應如何書寫的示例:

using IronPdf;
using System;
using System.Web.Mvc;

namespace WebApplication8.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            // Render a URL as PDF and return it in the response
            using var pdf = HtmlToPdf.StaticRenderUrlAsPdf(new Uri("https://en.wikipedia.org"));
            return File(pdf.BinaryData, "application/pdf", "Wiki.Pdf");
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }
    }
}
using IronPdf;
using System;
using System.Web.Mvc;

namespace WebApplication8.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            // Render a URL as PDF and return it in the response
            using var pdf = HtmlToPdf.StaticRenderUrlAsPdf(new Uri("https://en.wikipedia.org"));
            return File(pdf.BinaryData, "application/pdf", "Wiki.Pdf");
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";
            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";
            return View();
        }
    }
}
Imports IronPdf
Imports System
Imports System.Web.Mvc

Namespace WebApplication8.Controllers
	Public Class HomeController
		Inherits Controller

		Public Function Index() As ActionResult
			' Render a URL as PDF and return it in the response
			Dim pdf = HtmlToPdf.StaticRenderUrlAsPdf(New Uri("https://en.wikipedia.org"))
			Return File(pdf.BinaryData, "application/pdf", "Wiki.Pdf")
		End Function

		Public Function About() As ActionResult
			ViewBag.Message = "Your application description page."
			Return View()
		End Function

		Public Function Contact() As ActionResult
			ViewBag.Message = "Your contact page."
			Return View()
		End Function
	End Class
End Namespace
$vbLabelText   $csharpLabel

向PDF文檔添加封面

如何使用C#和IronPDF在ASP.NET中查看PDF文件,圖1:向PDF文檔添加封面 向PDF文檔添加封面頁

IronPDF簡化了合併PDF文檔的過程。 這種技術最常見的應用是向已渲染的PDF文檔添加封面或背面。

為此,準備一個封面頁,然後使用PdfDocument的功能。

要合併這兩個文檔,請使用合併PDF文檔方法

// Create a renderer and render a PDF from a URL
var renderer = new ChromePdfRenderer();
using var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/");

// Merge the cover page with the rendered PDF
using var merged = PdfDocument.Merge(new PdfDocument("CoverPage.pdf"), pdf);

// Save the merged document
merged.SaveAs("Combined.Pdf");
// Create a renderer and render a PDF from a URL
var renderer = new ChromePdfRenderer();
using var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/");

// Merge the cover page with the rendered PDF
using var merged = PdfDocument.Merge(new PdfDocument("CoverPage.pdf"), pdf);

// Save the merged document
merged.SaveAs("Combined.Pdf");
' Create a renderer and render a PDF from a URL
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/")

' Merge the cover page with the rendered PDF
Dim merged = PdfDocument.Merge(New PdfDocument("CoverPage.pdf"), pdf)

' Save the merged document
merged.SaveAs("Combined.Pdf")
$vbLabelText   $csharpLabel

給您的文檔添加水印

最後但同樣重要的是,使用C#代碼可以在PDF文檔中添加水印; 這可以用來向文檔的每頁添加聲明,說明它是“機密”或“示例”。

// Prepare a stamper with HTML content for the watermark
HtmlStamper stamper = new HtmlStamper("<h2 style='color:red'>SAMPLE</h2>")
{
    HorizontalOffset = new Length(-3, MeasurementUnit.Inch),
    VerticalAlignment = VerticalAlignment.Bottom
};

// Create a renderer and render a PDF from a URL
var renderer = new ChromePdfRenderer();
using var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");

// Apply the watermark to the PDF
pdf.ApplyStamp(stamper);

// Save the watermarked PDF
pdf.SaveAs(@"C:\PathToWatermarked.pdf");
// Prepare a stamper with HTML content for the watermark
HtmlStamper stamper = new HtmlStamper("<h2 style='color:red'>SAMPLE</h2>")
{
    HorizontalOffset = new Length(-3, MeasurementUnit.Inch),
    VerticalAlignment = VerticalAlignment.Bottom
};

// Create a renderer and render a PDF from a URL
var renderer = new ChromePdfRenderer();
using var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");

// Apply the watermark to the PDF
pdf.ApplyStamp(stamper);

// Save the watermarked PDF
pdf.SaveAs(@"C:\PathToWatermarked.pdf");
' Prepare a stamper with HTML content for the watermark
Dim stamper As New HtmlStamper("<h2 style='color:red'>SAMPLE</h2>") With {
	.HorizontalOffset = New Length(-3, MeasurementUnit.Inch),
	.VerticalAlignment = VerticalAlignment.Bottom
}

' Create a renderer and render a PDF from a URL
Dim renderer = New ChromePdfRenderer()
Dim pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")

' Apply the watermark to the PDF
pdf.ApplyStamp(stamper)

' Save the watermarked PDF
pdf.SaveAs("C:\PathToWatermarked.pdf")
$vbLabelText   $csharpLabel

您的PDF文件可以通過設置密碼進行保護

當您設置PDF文檔的密碼屬性時,將會對其進行加密,用戶需要提供正確的密碼才能閱讀文檔。 此示例可以在.NET Core控制台應用程式中使用。

using IronPdf;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a renderer and render a PDF from HTML
            var renderer = new ChromePdfRenderer();
            using var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

            // Set password to protect the PDF
            pdfDocument.Password = "strong!@#pass&^%word";

            // Save the secured PDF
            pdfDocument.SaveAs("secured.pdf");
        }
    }
}
using IronPdf;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a renderer and render a PDF from HTML
            var renderer = new ChromePdfRenderer();
            using var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");

            // Set password to protect the PDF
            pdfDocument.Password = "strong!@#pass&^%word";

            // Save the secured PDF
            pdfDocument.SaveAs("secured.pdf");
        }
    }
}
Imports IronPdf

Namespace ConsoleApp
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			' Create a renderer and render a PDF from HTML
			Dim renderer = New ChromePdfRenderer()
			Dim pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>")

			' Set password to protect the PDF
			pdfDocument.Password = "strong!@#pass&^%word"

			' Save the secured PDF
			pdfDocument.SaveAs("secured.pdf")
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

沒有上述的優勢,使用IronPDF您還可以:

創建PDF是一項具有挑戰性的工作; 有些人可能從未接觸過他們應該使用哪些基本概念來創建最出色的文檔。 因此,IronPDF非常有幫助,因為它簡化了創建PDF的過程,並因此改善了從PDF和HTML創建的文檔的原始演示。

根據文檔中提供的信息和競爭對手分析:IronPDF是創建PDF時最有效的工具,使其對任何人,包括在辦公室或學校工作的人而言簡單易行,以高效地完成他們的任務。

如何使用C#和IronPDF在ASP.NET中查看PDF文件,圖2:如何使用C#和IronPDF在ASP.NET中查看PDF文件 如何使用C#和IronPDF在ASP.NET中查看PDF文件

IronPDF是一個必備的.NET庫。 立即獲得您的與IronPDF NuGet包一起嘗試

常見問題解答

如何使用 C# 在 ASP.NET 應用程式中查看 PDF 檔案?

您可以使用 IronPDF 在 ASP.NET 應用程式中查看 PDF 文件,方法是將 PDF 渲染為圖像或可嵌入網頁中的 HTML 元素。

在 ASP.NET 中,如何將 HTML 頁面轉換為 PDF?

要在 ASP.NET 中將 HTML 頁面轉換為 PDF,可以使用 IronPDF 的RenderHtmlAsPdf方法,該方法支援 CSS 和 JavaScript 以實現精確渲染。

如何在C#中合併多個PDF文件?

IronPDF 讓您可以使用PdfDocument.Merge方法合併多個 PDF 文檔,該方法可以將不同的 PDF 文件合併為一個文檔。

是否可以在 ASP.NET 中為 PDF 文件添加浮水印?

是的,您可以使用 IronPDF 在 ASP.NET 中為 PDF 文件添加浮水印,方法是使用HtmlStamper類別覆寫自訂 HTML 內容。

如何使用 C# 對 PDF 檔案實現密碼保護?

您可以使用 IronPDF 對 PDF 檔案實施密碼保護,方法是在PdfDocument上設定Password屬性以加密檔案。

IronPDF 能否將 ASP.NET Web Forms 轉換為 PDF?

是的,IronPDF 可以使用RenderThisPageAsPdf等方法將 ASP.NET Web Forms 轉換為 PDF,將整個 Web 表單擷取為 PDF 文件。

IronPDF 在 ASP.NET 中產生 PDF 有哪些優勢?

IronPDF 具有許多優勢,例如使用內建的 Google Chromium 引擎精確渲染 HTML、CSS 和 JavaScript,使其成為 ASP.NET 中產生 PDF 的靈活工具。

如何在我的 ASP.NET 專案中安裝 IronPDF?

您可以透過 NuGet 套件管理器將 IronPDF 安裝到您的 ASP.NET 專案中,或直接從 IronPDF 網站下載 DLL 檔案。

IronPDF為何對軟體開發人員來說是一項寶貴的資產?

IronPDF 對軟體開發人員來說是一個寶貴的資產,因為它簡化了複雜的 PDF 生成任務,並能無縫整合到 ASP.NET 應用程式中,從而有效率地處理 PDF。

如何使用 IronPDF 在 C# 中透過 URL 建立 PDF 檔案?

您可以使用 IronPDF 的RenderUrlAsPdf方法在 C# 中從 URL 建立 PDF,該方法會從 URL 取得內容並將其轉換為 PDF 文件。

.NET 10 支援:IronPDF 是否相容於 .NET 10,以便在 ASP.NET 中查看 PDF 檔案?

是的-IronPDF 完全支援 .NET 10,包括使用 ASP.NET 或 ASP.NET Core 的 Web 應用程式。它無需特殊配置即可在 .NET 10 專案中無縫運行。您仍然可以像在早期 .NET 版本中一樣使用熟悉的方法,例如RenderUrlAsPdf或傳回 MIME 類型為application/pdfFileStreamResult旨在實現跨平台支持,並且 .NET 10 已明確列入其支援的框架之一。 ([ironpdf.com](https://ironpdf.com/?utm_source=openai))

Curtis Chau
技術作家

Curtis Chau 擁有卡爾頓大學計算機科學學士學位,專注於前端開發,擅長於 Node.js、TypeScript、JavaScript 和 React。Curtis 熱衷於創建直觀且美觀的用戶界面,喜歡使用現代框架並打造結構良好、視覺吸引人的手冊。

除了開發之外,Curtis 對物聯網 (IoT) 有著濃厚的興趣,探索將硬體和軟體結合的創新方式。在閒暇時間,他喜愛遊戲並構建 Discord 機器人,結合科技與創意的樂趣。