跳過到頁腳內容
.NET幫助

Hangfire .NET Core(開發者的工作原理)

現代應用程式開發通常需要處理背景任務,以處理龐大的工作量。 在這種情況下,我們需要能夠執行多個工作的背景工作處理程式。 C# .NET Core 應用程式的背景工作處理程式就是其中之一,它就是 Hangfire。在本篇部落格中,我們將學習如何管理 Hangfire 背景作業,以及如何與其他套件搭配使用,例如 IronPDF for PDF Generation 以在背景中產生 PDF 文件。

Hangfire 透過提供可靠且彈性的框架來管理和執行背景工作,簡化了 ASP.NET Core 或 .NET Core 6 Web API 應用程式中背景處理的執行。 Hangfire 以 NuGet 套件的形式提供,可使用 .NET CLI 安裝,如下所示:

dotnet add package Hangfire --version 1.8.6

在 .NET Core Web API 中實作。

要了解 Hangfire,讓我們建立一個簡單的 .NET Core API 應用程式,並使用 CLI 安裝 Hangfire。

dotnet new webapi -n HangfireDemo
cd HangfireDemo
dotnet build
dotnet add package Hangfire --version 1.8.6
dotnet build
dotnet new webapi -n HangfireDemo
cd HangfireDemo
dotnet build
dotnet add package Hangfire --version 1.8.6
dotnet build
SHELL

在此,我們使用 .NET CLI 建立一個簡單的天氣 REST API。 第一行建立了一個名為 HangfireDemo 的 .NET Core Web API 項目,用於執行 API 端點。 第二行會導航到我們新建立的資料夾"HangfireDemo",然後建立專案。 接下來,我們將 Hangfire NuGet 套件加入專案,並再次建立專案。 之後,您可以在您選擇的任何編輯器中開啟專案,例如 Visual Studio 2022 或 JetBrains Rider。 現在如果您執行專案,可以看到 Swagger 如下所示:

Hangfire .NET Core (How It Works For Developer):圖 1 - Swagger

這裡我們可以看到天氣 GET API,它會回傳日期、摘要和溫度。

Hangfire .NET Core (How It Works For Developer):圖 2 - 天氣 GET API

現在讓我們加入 Hangfire 背景工作處理器。 在 Visual Studio 中開啟專案。

新增 Hangfire 工作處理器

在您的應用程式中設定 Hangfire,通常是在 Startup.cs 檔案中。這包括設定作業儲存和初始化 Hangfire 伺服器。

// Startup.cs
using Hangfire;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add Hangfire services and use SQL Server as storage option
        services.AddHangfire(config => config.UseSqlServerStorage("your_connection_string"));
        services.AddHangfireServer();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // Use Hangfire Server and Dashboard for monitoring and managing jobs
        app.UseHangfireServer();
        app.UseHangfireDashboard();
        // Your other configuration settings
    }
}
// Startup.cs
using Hangfire;

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        // Add Hangfire services and use SQL Server as storage option
        services.AddHangfire(config => config.UseSqlServerStorage("your_connection_string"));
        services.AddHangfireServer();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        // Use Hangfire Server and Dashboard for monitoring and managing jobs
        app.UseHangfireServer();
        app.UseHangfireDashboard();
        // Your other configuration settings
    }
}
' Startup.cs
Imports Hangfire

Public Class Startup
	Public Sub ConfigureServices(ByVal services As IServiceCollection)
		' Add Hangfire services and use SQL Server as storage option
		services.AddHangfire(Function(config) config.UseSqlServerStorage("your_connection_string"))
		services.AddHangfireServer()
	End Sub

	Public Sub Configure(ByVal app As IApplicationBuilder, ByVal env As IHostingEnvironment)
		' Use Hangfire Server and Dashboard for monitoring and managing jobs
		app.UseHangfireServer()
		app.UseHangfireDashboard()
		' Your other configuration settings
	End Sub
End Class
$vbLabelText   $csharpLabel

ConfigureServices 方法用於新增儲存空間以保存 Hangfire 新建立的作業。 這裡使用的是 SQL Server 資料庫。 SQL Server 連線字串應替換為 "your_connection_string"。 人們也可以使用 Hangfire.InMemory 的記憶體儲存。

dotnet add package Hangfire.InMemory --version 0.6.0

並取代為

services.AddHangfire(configuration => { configuration.UseInMemoryStorage(); });
services.AddHangfire(configuration => { configuration.UseInMemoryStorage(); });
services.AddHangfire(Sub(configuration)
	configuration.UseInMemoryStorage()
End Sub)
$vbLabelText   $csharpLabel

建立背景工作。

定義您希望作為背景工作執行的方法。 這些方法應該是靜態或具有無參數構造器類的實例方法。 工作可以以經常性工作的方式執行,也可以同時執行多個工作。

public class MyBackgroundJob
{
    public void ProcessJob()
    {
        // Background job logic, can be a recurring job or multiple jobs
        Console.WriteLine("Background job is running...");
    }
}
public class MyBackgroundJob
{
    public void ProcessJob()
    {
        // Background job logic, can be a recurring job or multiple jobs
        Console.WriteLine("Background job is running...");
    }
}
Public Class MyBackgroundJob
	Public Sub ProcessJob()
		' Background job logic, can be a recurring job or multiple jobs
		Console.WriteLine("Background job is running...")
	End Sub
End Class
$vbLabelText   $csharpLabel

任務入隊

使用 Hangfire API 匯入背景工作。 您可以排程背景工作在特定時間、延遲後或定期執行。

// Enqueue a job to run immediately
BackgroundJob.Enqueue<MyBackgroundJob>(x => x.ProcessJob());

// Schedule a job to run after a 5-minute delay
BackgroundJob.Schedule<MyBackgroundJob>(x => x.ProcessJob(), TimeSpan.FromMinutes(5));

// Schedule a recurring job using a job ID
RecurringJob.AddOrUpdate<MyBackgroundJob>("jobId", x => x.ProcessJob(), Cron.Daily);
// Enqueue a job to run immediately
BackgroundJob.Enqueue<MyBackgroundJob>(x => x.ProcessJob());

// Schedule a job to run after a 5-minute delay
BackgroundJob.Schedule<MyBackgroundJob>(x => x.ProcessJob(), TimeSpan.FromMinutes(5));

// Schedule a recurring job using a job ID
RecurringJob.AddOrUpdate<MyBackgroundJob>("jobId", x => x.ProcessJob(), Cron.Daily);
' Enqueue a job to run immediately
BackgroundJob.Enqueue(Of MyBackgroundJob)(Function(x) x.ProcessJob())

' Schedule a job to run after a 5-minute delay
BackgroundJob.Schedule(Of MyBackgroundJob)(Function(x) x.ProcessJob(), TimeSpan.FromMinutes(5))

' Schedule a recurring job using a job ID
RecurringJob.AddOrUpdate(Of MyBackgroundJob)("jobId", Function(x) x.ProcessJob(), Cron.Daily)
$vbLabelText   $csharpLabel

Hangfire Dashboard 和 Server

可透過 Configure 方法新增 Hangfire 儀表板和伺服器,以實現即時作業監控。

// Run Hangfire server and dashboard
app.UseHangfireServer();
app.UseHangfireDashboard();
// Run Hangfire server and dashboard
app.UseHangfireServer();
app.UseHangfireDashboard();
' Run Hangfire server and dashboard
app.UseHangfireServer()
app.UseHangfireDashboard()
$vbLabelText   $csharpLabel

伺服器也可以加入到 ConfigureServices

services.AddHangfireServer();
services.AddHangfireServer();
services.AddHangfireServer()
$vbLabelText   $csharpLabel

即開即棄工作

// Fire and forget jobs are executed only once and almost immediately after creation.
var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget!")); // Job ID for fire and forget job
// Fire and forget jobs are executed only once and almost immediately after creation.
var jobId = BackgroundJob.Enqueue(() => Console.WriteLine("Fire-and-forget!")); // Job ID for fire and forget job
' Fire and forget jobs are executed only once and almost immediately after creation.
Dim jobId = BackgroundJob.Enqueue(Sub() Console.WriteLine("Fire-and-forget!")) ' Job ID for fire and forget job
$vbLabelText   $csharpLabel

經常性工作

// Recurring jobs fire many times based on a specified CRON schedule.
RecurringJob.AddOrUpdate("myrecurringjob", () => Console.WriteLine("Recurring!"), Cron.Daily);
// Recurring jobs fire many times based on a specified CRON schedule.
RecurringJob.AddOrUpdate("myrecurringjob", () => Console.WriteLine("Recurring!"), Cron.Daily);
' Recurring jobs fire many times based on a specified CRON schedule.
RecurringJob.AddOrUpdate("myrecurringjob", Sub() Console.WriteLine("Recurring!"), Cron.Daily)
$vbLabelText   $csharpLabel

延遲的工作

// Delayed jobs are executed only once but after a specified interval.
var jobId = BackgroundJob.Schedule(() => Console.WriteLine("Delayed!"), TimeSpan.FromDays(7));
// Delayed jobs are executed only once but after a specified interval.
var jobId = BackgroundJob.Schedule(() => Console.WriteLine("Delayed!"), TimeSpan.FromDays(7));
' Delayed jobs are executed only once but after a specified interval.
Dim jobId = BackgroundJob.Schedule(Sub() Console.WriteLine("Delayed!"), TimeSpan.FromDays(7))
$vbLabelText   $csharpLabel

續篇

// Continuation jobs are executed once their parent jobs have completed.
BackgroundJob.ContinueJobWith(jobId, () => Console.WriteLine("Continuation!"));
// Continuation jobs are executed once their parent jobs have completed.
BackgroundJob.ContinueJobWith(jobId, () => Console.WriteLine("Continuation!"));
' Continuation jobs are executed once their parent jobs have completed.
BackgroundJob.ContinueJobWith(jobId, Sub() Console.WriteLine("Continuation!"))
$vbLabelText   $csharpLabel

批量工作

// Batch is a group of background jobs created atomically and considered as a single entity.
var batchId = BatchJob.StartNew(x =>
{
    x.Enqueue(() => Console.WriteLine("Job 1"));
    x.Enqueue(() => Console.WriteLine("Job 2"));
});
// Batch is a group of background jobs created atomically and considered as a single entity.
var batchId = BatchJob.StartNew(x =>
{
    x.Enqueue(() => Console.WriteLine("Job 1"));
    x.Enqueue(() => Console.WriteLine("Job 2"));
});
' Batch is a group of background jobs created atomically and considered as a single entity.
Dim batchId = BatchJob.StartNew(Sub(x)
	x.Enqueue(Sub() Console.WriteLine("Job 1"))
	x.Enqueue(Sub() Console.WriteLine("Job 2"))
End Sub)
$vbLabelText   $csharpLabel

批次延續工作

// Batch continuation is fired when all background jobs in a parent batch are finished.
BatchJob.ContinueBatchWith(batchId, x =>
{
    x.Enqueue(() => Console.WriteLine("Last Job"));
});
// Batch continuation is fired when all background jobs in a parent batch are finished.
BatchJob.ContinueBatchWith(batchId, x =>
{
    x.Enqueue(() => Console.WriteLine("Last Job"));
});
' Batch continuation is fired when all background jobs in a parent batch are finished.
BatchJob.ContinueBatchWith(batchId, Sub(x)
	x.Enqueue(Sub() Console.WriteLine("Last Job"))
End Sub)
$vbLabelText   $csharpLabel

儀表板

Hangfire Dashboard 是您可以找到所有背景工作資訊的地方。 它是以 OWIN 中介軟體的方式寫成 (如果您不熟悉 OWIN,也不用擔心),因此您可以將它插入 ASP.NET、ASP.NET MVC、Nancy 和 ServiceStack 應用程式中,也可以使用 OWIN Self-Host 功能將 Dashboard 寄存在 Console Applications 或 Windows Services 內。

啟用儀表板後,可透過 /hangfire/ 擴充功能存取。 在此儀表板中,您可以管理背景執行中的工作、排程背景工作,並檢視"啟動與遺忘"工作以及重複性工作。 這些工作可以使用工作 ID 來識別。

即時處理

Hangfire .NET Core (How It Works For Developer):圖 3 - 工作的即時處理

成功的工作

檢視以下成功的工作。

Hangfire .NET Core (How It Works For Developer):圖 4 - 成功的工作

排程工作

Hangfire .NET Core (How It Works For Developer):圖 5 - 排程工作

當您的應用程式執行時,Hangfire 會根據設定來處理背景工作。

請記得查看 Hangfire 文件,以瞭解更多進階的設定選項和功能:Hangfire Documentation 和完整程式碼可在 GitHub Hangfire Demo 上找到。

介紹 IronPDF。

IronPDF 適用於 .NET PDF GenerationIron Software 的 PDF Library 中的 NuGet 套件,可協助讀取和產生 PDF 文件。 它可以將格式簡單、包含樣式資訊的文件轉換成 PDF。 IronPDF 可以輕鬆地從 HTML 內容產生 PDF。 它可以從 URL 下載 HTML,然後產生 PDF。

IronPDF 的主要魅力在於它的 HTML 至 PDF 轉換功能,可保留版面與樣式。 它可以從網頁內容建立 PDF,是報告、發票和文件的理想選擇。 此功能支援將 HTML 檔案、URL 和 HTML 字串轉換為 PDF。

using IronPdf;

class Program
{
    static void Main(string[] args)
    {
        var renderer = new ChromePdfRenderer();

        // Convert HTML String to PDF
        var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
        var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
        pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");

        // Convert HTML File to PDF
        var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
        var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
        pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");

        // Convert URL to PDF
        var url = "http://ironpdf.com"; // Specify the URL
        var pdfFromUrl = renderer.RenderUrlAsPdf(url);
        pdfFromUrl.SaveAs("URLToPDF.pdf");
    }
}
using IronPdf;

class Program
{
    static void Main(string[] args)
    {
        var renderer = new ChromePdfRenderer();

        // Convert HTML String to PDF
        var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>";
        var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent);
        pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf");

        // Convert HTML File to PDF
        var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file
        var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath);
        pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf");

        // Convert URL to PDF
        var url = "http://ironpdf.com"; // Specify the URL
        var pdfFromUrl = renderer.RenderUrlAsPdf(url);
        pdfFromUrl.SaveAs("URLToPDF.pdf");
    }
}
Imports IronPdf

Friend Class Program
	Shared Sub Main(ByVal args() As String)
		Dim renderer = New ChromePdfRenderer()

		' Convert HTML String to PDF
		Dim htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"
		Dim pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent)
		pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf")

		' Convert HTML File to PDF
		Dim htmlFilePath = "path_to_your_html_file.html" ' Specify the path to your HTML file
		Dim pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath)
		pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf")

		' Convert URL to PDF
		Dim url = "http://ironpdf.com" ' Specify the URL
		Dim pdfFromUrl = renderer.RenderUrlAsPdf(url)
		pdfFromUrl.SaveAs("URLToPDF.pdf")
	End Sub
End Class
$vbLabelText   $csharpLabel

開始使用 IronPDF

安裝 IronPDF Library

使用 NuGet 套件管理員安裝

若要使用 NuGet Package Manager 將 IronPDF 整合至您的 Hangfire .NET 專案,請遵循下列步驟:

1.開啟 Visual Studio,並在"解決方案總管"中,用滑鼠右鍵按一下專案。 2.從上下文功能表中選擇"管理 NuGet 套件..."。 3.前往瀏覽索引標籤,搜尋 IronPDF。 4.從搜尋結果中選擇 IronPDF 函式庫,然後按一下安裝按鈕。 5.接受任何許可協議提示。

如果您偏好使用套件管理員控制台,請執行下列指令:

Install-Package IronPdf

這將取得 IronPDF 並將其安裝到您的專案中。

使用 NuGet 網站安裝

如需 IronPDF 的詳細概述,包括功能、相容性和其他下載選項,請造訪 NuGet 網站上的 IronPDF 頁面,網址為 https://www.nuget.org/packages/IronPdf

透過 DLL 安裝

另外,您也可以使用 IronPDF 的 DLL 檔案,直接將 IronPDF 納入您的專案中。從此 IronPDF Direct Download 下載包含 DLL 的 ZIP 檔案。 解壓縮,並將 DLL 包含在您的專案中。

現在讓我們修改應用程式,加入背景處理工作,將網站下載為 PDF 檔案。

namespace HangfireDemo.Core;

public class PdfGenerationJob
{
    public void Start(string website)
    {
        // Create a PDF from any existing web page
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderUrlAsPdf(website);
        var filePath = AppContext.BaseDirectory + "result.pdf";
        pdf.SaveAs(filePath);
    }
}
namespace HangfireDemo.Core;

public class PdfGenerationJob
{
    public void Start(string website)
    {
        // Create a PDF from any existing web page
        ChromePdfRenderer renderer = new ChromePdfRenderer();
        PdfDocument pdf = renderer.RenderUrlAsPdf(website);
        var filePath = AppContext.BaseDirectory + "result.pdf";
        pdf.SaveAs(filePath);
    }
}
Namespace HangfireDemo.Core

	Public Class PdfGenerationJob
		Public Sub Start(ByVal website As String)
			' Create a PDF from any existing web page
			Dim renderer As New ChromePdfRenderer()
			Dim pdf As PdfDocument = renderer.RenderUrlAsPdf(website)
			Dim filePath = AppContext.BaseDirectory & "result.pdf"
			pdf.SaveAs(filePath)
		End Sub
	End Class
End Namespace
$vbLabelText   $csharpLabel

IronPDF 內建了從 URL 下載網站並儲存為 PDF 文件的方法。 我們要在工作中使用此方法下載並儲存至指定位置。 此背景工作可修改為取得多個網站 URL 並將其儲存為 PDF。

現在,讓我們新增一個控制器,以揭露 PDF 產生和下載 API。

using Hangfire;
using HangfireDemo.Core;
using Microsoft.AspNetCore.Mvc;

namespace HangfireDemo.Controllers;

[ApiController]
[Route("[controller]")]
public class PdfGeneratorController : ControllerBase
{
    [HttpGet("request", Name = "Start PDF Generation")]
    public void Start([FromQuery] string websiteUrl)
    {
        BackgroundJob.Enqueue<PdfGenerationJob>(x => x.Start(websiteUrl));
    }

    [HttpGet("result", Name = "Download PDF Generation")]
    public IActionResult WebResult()
    {
        var filePath = AppContext.BaseDirectory + "result.pdf";
        var stream = new FileStream(filePath, FileMode.Open);
        return new FileStreamResult(stream, "application/octet-stream") { FileDownloadName = "website.pdf" };
    }
}
using Hangfire;
using HangfireDemo.Core;
using Microsoft.AspNetCore.Mvc;

namespace HangfireDemo.Controllers;

[ApiController]
[Route("[controller]")]
public class PdfGeneratorController : ControllerBase
{
    [HttpGet("request", Name = "Start PDF Generation")]
    public void Start([FromQuery] string websiteUrl)
    {
        BackgroundJob.Enqueue<PdfGenerationJob>(x => x.Start(websiteUrl));
    }

    [HttpGet("result", Name = "Download PDF Generation")]
    public IActionResult WebResult()
    {
        var filePath = AppContext.BaseDirectory + "result.pdf";
        var stream = new FileStream(filePath, FileMode.Open);
        return new FileStreamResult(stream, "application/octet-stream") { FileDownloadName = "website.pdf" };
    }
}
Imports Hangfire
Imports HangfireDemo.Core
Imports Microsoft.AspNetCore.Mvc

Namespace HangfireDemo.Controllers

	<ApiController>
	<Route("[controller]")>
	Public Class PdfGeneratorController
		Inherits ControllerBase

		<HttpGet("request", Name := "Start PDF Generation")>
		Public Sub Start(<FromQuery> ByVal websiteUrl As String)
			BackgroundJob.Enqueue(Of PdfGenerationJob)(Function(x) x.Start(websiteUrl))
		End Sub

		<HttpGet("result", Name := "Download PDF Generation")>
		Public Function WebResult() As IActionResult
			Dim filePath = AppContext.BaseDirectory & "result.pdf"
			Dim stream = New FileStream(filePath, FileMode.Open)
			Return New FileStreamResult(stream, "application/octet-stream") With {.FileDownloadName = "website.pdf"}
		End Function
	End Class
End Namespace
$vbLabelText   $csharpLabel

在此我們建立了兩個 API:一個用來啟動背景工作並取得網站 URL 以啟動下載,另一個 API 則用來下載結果 PDF。 API 的描述如下所示。

Hangfire .NET Core (How It Works For Developer):圖 7 - PDFGenerator APIs

結果是這樣的

Hangfire .NET Core (How It Works For Developer):圖 8 - 輸出

授權(可免費試用)

若要使上述程式碼在沒有水印的情況下運作,必須取得授權金鑰。 開發人員註冊IronPDF免費試用後,即可獲得試用授權。 試用授權不需要信用卡。 您可以提供您的電子郵件 ID 並註冊免費試用。

結論

Hangfire 和 IronPDF 在一起是在背景中產生和下載 PDF 的絕佳組合。 Hangfire 可以高效處理長時間執行的任務,而 IronPDF 則為 PDF 產生提供了靈活易用的解決方案。 要瞭解有關 IronPDF 的更多資訊,您可以造訪 IronPDF說明文件

此外,還可探索 Iron Software 產品套件中的其他工具,這些工具可提升您的編碼技巧並滿足現代應用程式的需求。

常見問題解答

什麼是 .NET Core 中的 Hangfire?

Hangfire 是一個框架,簡化了在 ASP.NET Core 或 .NET Core 6 應用程式中實現背景處理的過程。它提供了一個可靠且靈活的方案,用於管理和執行背景工作。

如何在 .NET Core 應用程式中安裝 Hangfire?

Hangfire 可以作為 NuGet 套件安裝。您可以使用 .NET CLI 添加它,指令為:dotnet add package Hangfire --version 1.8.6

Hangfire 支援哪些類型的背景工作?

Hangfire 支援各種背景工作類型,包括即時工作、延遲工作、定期工作和續作工作。

如何在 .NET Core 應用程式中配置 Hangfire?

Hangfire 規範在 Startup.cs 文件中,在此您設置工作儲存並初始化 Hangfire 伺服器。通常涉及添加 Hangfire 服務並設置 SQL Server 或記憶體儲存。

什麼是 Hangfire 控制台?

Hangfire 控制板是一個用於監控和管理背景工作的平台。它提供有關實時處理、已成功完成的工作和計劃中工作的資訊,可通過網頁界面訪問。

如何使用 Hangfire 創建背景工作?

可以通過在 Hangfire 中定義您想運行的方法並使用 Hangfire API 排隊他們來創建背景工作。工作可以立即安排、延遲後或定期運行。

如何在 .NET Core 中執行 PDF 生成任務於背景?

您可以通過支持 HTML 到 PDF 轉換的 PDF 庫在背景中執行 PDF 生成任務。這可以集成到像 Hangfire 這樣的背景工作處理框架中,以自動化從 HTML 內容生成 PDF。

在 .NET 中 PDF 生成庫有什麼功能?

PDF 生成庫可以將 HTML 字串、HTML 文件和 URL 轉換為 PDF。它保留布局和樣式,對於生成報告、發票和從網頁內容建立的文檔非常有用。

如何在 .NET 專案中安裝 PDF 生成庫?

可以通過 Visual Studio 中的 NuGet 套件管理器或通過套件管理器控制台以特定命令來安裝 PDF 生成庫。也可以通過從庫網站下載 DLL 直接安裝。

使用無浮水印的 PDF 生成庫需要什麼?

要使用無浮水印的 PDF 生成庫,通常需要授權密鑰。可以通過在庫網站註冊獲得免費試用授權。

如何將 PDF 生成工具與 .NET Core 中的 Hangfire 集成?

可以通過建立使用 PDF 生成庫的背景工作將 PDF 生成工具與 .NET Core 中的 Hangfire 集成,這允許在應用程式中自動化文檔創建和管理。

Jacob Mellor, Team Iron 首席技術官
首席技術官

Jacob Mellor是Iron Software的首席技術官,也是開創C# PDF技術的前瞻性工程師。作為Iron Software核心代碼庫的原始開發者,他自公司成立以來就塑造了公司的產品架構,並與CEO Cameron Rimington將公司轉型為服務NASA、Tesla以及全球政府機構的50多人公司。

Jacob擁有曼徹斯特大學土木工程一級榮譽學士學位(1998年–2001年)。他於1999年在倫敦開立首家軟體公司,並於2005年建立了他的第一個.NET組件,專注於解決Microsoft生態系統中的複雜問題。

他的旗艦作品IronPDF和Iron Suite .NET程式庫全球已獲得超過3000萬次NuGet安裝,他的基礎代碼不斷在全球各地驅動開發者工具。擁有25年以上的商業經驗和41年的編碼專業知識,Jacob仍然專注於推動企業級C#、Java和Python PDF技術的創新,同時指導下一代技術領導者。

鋼鐵支援團隊

我們每週 5 天,每天 24 小時在線上。
聊天
電子郵件
打電話給我