如何在 C# 中將 WebGL 網站渲染為 PDF

How to Render WebGL Sites

This article was translated from English: Does it need improvement?
Translated
View the article in English
class="container-fluid">
class="row">
class="col-md-2"> Webgl Logo related to How to Render WebGL Sites

WebGL 是在網頁瀏覽器中創建互動 3D 圖形的強大工具,但要將這些動態、高度互動的體驗轉換為靜態 PDF 格式可能具有挑戰性。 將 WebGL 網站渲染為 PDF 涉及捕獲由 WebGL 上下文生成的視覺內容,並將其轉換為適合於 PDF 文件的格式。

IronPDF provides the tools needed to capture and render websites with WebGL such as Mapbox and the WebGL Samples collection.

快速入門:將 WebGL 內容渲染為 PDF 在 .NET

使用 IronPDF 在 .NET C# 中輕鬆將互動的 WebGL 圖形轉換為靜態 PDF。 本指南簡單明瞭,可幫助您快速設置和渲染網站的 WebGL 內容。 透過將 Chrome GPU 模式設定為硬體並啟用單一進程,您可以有效地捕獲動態網頁圖形。 請按照以下步驟開始將 3D 網頁內容轉化為可分享的 PDF 文檔。

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronPDF with NuGet Package Manager

    PM > Install-Package IronPdf

  2. Copy and run this code snippet.

    IronPdf.Installation.SingleProcess = true; IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Hardware;
    new IronPdf.ChromePdfRenderer { RenderingOptions = { WaitFor = IronPdf.Rendering.WaitFor.RenderDelay(5000) } }
        .RenderUrlAsPdf("https://example.com/webgl‑demo")
        .SaveAs("webgl‑output.pdf");
  3. Deploy to test on your live environment

    Start using IronPDF in your project today with a free trial
    arrow pointer
class="hsg-featured-snippet">

最小工作流程(5 步)

  1. 下載 IronPDF C# 庫
  2. SingleProcess 屬性設置為 true
  3. ChromeGpuMode 屬性更改為硬體
  4. 在渲染前應用延遲以確保正確渲染
  5. 從 URL 渲染 PDF 並儲存結果


渲染 WebGL 網站

要啟用 WebGL 渲染,您需要配置幾個 IronPDF 設置:

  • SingleProcess = true。 這強制 Chrome 在當前過程中執行所有操作,而不是使用子進程。
  • ChromeGpuMode = Hardware 模式。

此外,如果網站在渲染前需要一些延遲才能正確顯示,您可以使用 WaitFor.RenderDelay 方法。 讓我們在例子中渲染一個來自 Mapbox 的 GeoJSON 層範例

:path=/static-assets/pdf/content-code-examples/how-to/render-webgl-render-webgl.cs
using IronPdf;

// Configure IronPdf settings
IronPdf.Installation.SingleProcess = true;
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Hardware;

ChromePdfRenderer renderer = new ChromePdfRenderer();

// Set delay before rendering
renderer.RenderingOptions.WaitFor.RenderDelay(5000);

// Render from URL
PdfDocument pdf = renderer.RenderUrlAsPdf("https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-slot/");

pdf.SaveAs("webGL.pdf");
Imports IronPdf

' Configure IronPdf settings
IronPdf.Installation.SingleProcess = True
IronPdf.Installation.ChromeGpuMode = IronPdf.Engines.Chrome.ChromeGpuModes.Hardware

Dim renderer As New ChromePdfRenderer()

' Set delay before rendering
renderer.RenderingOptions.WaitFor.RenderDelay(5000)

' Render from URL
Dim pdf As PdfDocument = renderer.RenderUrlAsPdf("https://docs.mapbox.com/mapbox-gl-js/example/geojson-layer-in-slot/")

pdf.SaveAs("webGL.pdf")
$vbLabelText   $csharpLabel

輸出PDF

目前在 Docker 環境中無法渲染 WebGL。因為 Docker 容器通常是無頭環境,意味著它們沒有圖形用戶界面(GUI),在 Docker 上渲染 WebGL 會很困難。 WebGL 依賴於訪問 GPU 來渲染圖形,而在無頭環境中,訪問 GPU 是有限的或不存在的。 我們的開發人員仍在調查這個可能性。 如果您希望在結果有了結論後獲得通知,請聯繫 support@ironsoftware.com

準備看看您還能做哪些其他事情嗎? 查看我們的教程頁面:附加功能

常見問題解答

如何在C#中將HTML轉換為PDF?

您可以使用 IronPDF 的RenderHtmlAsPdf方法將 HTML 字串轉換為 PDF。您也可以使用RenderHtmlFileAsPdf將 HTML 檔案轉換為 PDF。

什麼是WebGL?

WebGL 是一款功能強大的工具,用於在網頁瀏覽器中建立互動式 3D 圖形。它允許開發人員直接在瀏覽器中渲染圖形,而無需插件。

如何使用 IronPDF 將 WebGL 網站渲染成 PDF?

若要使用 IronPDF 將 WebGL 網站渲染為 PDF,請將SingleProcess屬性配置為 true,並將ChromeGpuMode配置為 Hardware。使用RenderDelay方法確保所有元素在渲染之前載入完畢。

為什麼將動態網頁內容渲染成PDF檔案具有挑戰性?

將動態網頁內容渲染成 PDF 是一項挑戰,因為它涉及捕獲各種網路技術生成的動態互動視覺內容,並將其轉換為適合 PDF 文件的靜態格式。

如何配置 IronPDF 以進行 WebGL 渲染?

為了實現高效的 WebGL 渲染,請將SingleProcess屬性設為 true,並將ChromeGpuMode設為 Hardware。使用RenderDelay方法新增延遲,以確保所有元素在渲染前完全載入。

能否在 Docker 環境下使用 IronPDF 渲染 WebGL?

不,目前無法在IronPDF的Docker環境中渲染WebGL。 Docker容器通常是無頭容器,缺乏WebGL渲染所需的GPU存取權。

在 IronPDF 中,渲染前施加延遲的目的是什麼?

IronPDF 中的RenderDelay設定用於在將網頁渲染為 PDF 之前新增延遲。這可以確保所有元素在捕獲之前完全加載並正確顯示。

我可以在哪裡下載 IronPDF C# 庫?

您可以從 NuGet 下載 IronPDF C# 庫,網址為 https://www.nuget.org/packages/IronPdf/。

GPU模式設定如何影響IronPDF中的渲染?

IronPDF 中的ChromeGpuMode屬性應設定為 Hardware,以允許 WebGL 利用硬體 GPU 進行渲染,從而實現 3D 圖形的有效擷取和渲染。

IronPDF 如何支援 .NET 10 進行 WebGL 渲染和 HTML 轉 PDF 任務?

IronPDF 與 .NET 10 完全相容,這表示您可以在 .NET 10 專案中無縫使用其所有 WebGL 渲染功能,例如設定SingleProcess 、將ChromeGpuMode設定為 Hardware 以及套用渲染延遲。它支援 HTML 轉 PDF、URL 渲染以及 .NET 10 運行時下的所有渲染選項。

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'name'

Filename: sections/author_component.php

Line Number: 18

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 18
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'title'

Filename: sections/author_component.php

Line Number: 38

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 38
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: Illegal string offset 'comment'

Filename: sections/author_component.php

Line Number: 48

Backtrace:

File: /var/www/ironpdf.com/application/views/main/sections/author_component.php
Line: 48
Function: _error_handler

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 63
Function: view

File: /var/www/ironpdf.com/application/views/products/sections/three_column_docs_page_structure.php
Line: 64
Function: main_view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/views/products/how-to/index.php
Line: 2
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 88
Function: view

File: /var/www/ironpdf.com/application/libraries/Render.php
Line: 552
Function: view

File: /var/www/ironpdf.com/application/controllers/Products/Howto.php
Line: 31
Function: render_products_view

File: /var/www/ironpdf.com/index.php
Line: 292
Function: require_once

準備好開始了嗎?
Nuget 下載 16,154,058 | 版本: 2025.11 剛剛發布