IRONSOFTWAREHOME
Razor 轉 PDF (Blazor Server)

// PM > Install-Package IronPdf.Extensions.Blazor

[Parameter]
public IEnumerable<PersonInfo> persons { get; set; }
public Dictionary<string, object> Parameters { get; set; } = new Dictionary<string, object>();

protected override async Task OnInitializedAsync()
{
    persons = new List<PersonInfo>
    {
        new PersonInfo { Name = "Alice", Title = "Mrs.", Description = "Software Engineer" },
        new PersonInfo { Name = "Bob", Title = "Mr.", Description = "Software Engineer" },
        new PersonInfo { Name = "Charlie", Title = "Mr.", Description = "Software Engineer" }
    };
}
private async void PrintToPdf()
{
    ChromePdfRenderer renderer = new ChromePdfRenderer();

    // Apply text footer
    renderer.RenderingOptions.TextFooter = new TextHeaderFooter()
        {
            LeftText = "{date} - {time}",
            DrawDividerLine = true,
            RightText = "Page {page} of {total-pages}",
            Font = IronSoftware.Drawing.FontTypes.Arial,
            FontSize = 11
        };

    Parameters.Add("persons", persons);

    // Render razor component to PDF
    PdfDocument pdf = renderer.RenderRazorComponentToPdf<Person>(Parameters);

    File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData);
}
' PM > Install-Package IronPdf.Extensions.Blazor

<Parameter>
Public Property persons As IEnumerable(Of PersonInfo)
Public Property Parameters As Dictionary(Of String, Object) = New Dictionary(Of String, Object)()

Protected Overrides Async Function OnInitializedAsync() As Task
    persons = New List(Of PersonInfo) From {
        New PersonInfo With {.Name = "Alice", .Title = "Mrs.", .Description = "Software Engineer"},
        New PersonInfo With {.Name = "Bob", .Title = "Mr.", .Description = "Software Engineer"},
        New PersonInfo With {.Name = "Charlie", .Title = "Mr.", .Description = "Software Engineer"}
    }
End Function

Private Async Sub PrintToPdf()
    Dim renderer As New ChromePdfRenderer()

    ' Apply text footer
    renderer.RenderingOptions.TextFooter = New TextHeaderFooter() With {
        .LeftText = "{date} - {time}",
        .DrawDividerLine = True,
        .RightText = "Page {page} of {total-pages}",
        .Font = IronSoftware.Drawing.FontTypes.Arial,
        .FontSize = 11
    }

    Parameters.Add("persons", persons)

    ' Render razor component to PDF
    Dim pdf As PdfDocument = renderer.RenderRazorComponentToPdf(Of Person)(Parameters)

    File.WriteAllBytes("razorComponentToPdf.pdf", pdf.BinaryData)
End Sub
NuGet Download
PM > Install-Package IronPdf
Razor 轉 PDF (Blazor Server)

Razor 轉 PDF (Blazor Server)

此範例展示了如何將Razor組件轉換成PDF文件。

IronPdf.Extensions.Blazor套件是主要IronPDF套件的擴展。 要將Razor組件的內容頁轉換為PDF,則需要IronPdf套件。

在下面的程式碼範例中,已經建立了一個名為**PersonInfo的模型。 在List中。 然後我們將Parameters**字典中的字串"persons"關聯起來。

ChromePdfRenderer類。 要將Razor組件轉換為PDF文件,我們使用RenderRazorComponentToPdf方法。 在程式碼範例中,我們將**Parameters**字典傳遞給渲染的方法。

學習在Blazor Server中將Razor組件轉換為PDF
在 GitHub 上查看

準備開始了嗎?

Nuget Downloads 20,878,335版本:2026.9剛剛發布

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費現場演示
Booking Badge

受到全球數百萬工程師的信任

Iron Software的客戶標誌
獲取您的無義務諮詢
填寫以下表格或電子郵件sales@ironsoftware.com
您的詳細資訊將始終保密
受到全球數百萬工程師的信任
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立