如何呈現 WebGL 網站
WebGL 是一個用於在網頁瀏覽器中創建互動式 3D 圖形的強大工具,但將這些動態且高度互動的體驗轉換成靜態 PDF 格式可能會有挑戰。 將 WebGL 網站渲染成 PDF 涉及捕獲 WebGL 上下文生成的視覺內容並將其轉換成適合 PDF 文件的格式。
IronPDF 提供了捕捉和渲染包含 WebGL 的網站所需的工具,如Mapbox和WebGL範例集.
開始使用 IronPDF
立即在您的專案中使用IronPDF,並享受免費試用。
如何呈現 WebGL 網站
- 下載 IronPDF C# 函式庫
- 設置 單一進程 將屬性設置為 true
- 更改 ChromeGpuMode 屬性到硬體
- 在呈現之前應用延遲以確保正確呈現
- 從 URL 渲染 PDF 並將結果保存
渲染 WebGL 網站
要啟用 WebGL 渲染,您需要配置一些 IronPDF 設置:
- SingleProcess = true. 這迫使 Chrome 在當前進程中執行所有操作,而不使用子進程。
ChromeGpuMode = 硬件 模式。
此外,如果網站需要在正確顯示之前延遲渲染,您可以使用
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")
輸出 PDF
目前在 Docker 環境中無法渲染 WebGL。因為 Docker 容器通常是無頭環境,這意味著它們沒有圖形用戶界面,這使得在 Docker 上渲染 WebGL 變得具有挑戰性。(圖形用戶介面). WebGL 依賴於訪問 GPU 來渲染圖形,在無頭環境中,訪問 GPU 的能力有限或不存在。 我們的開發人員仍在調查這個可能性。 如果您希望在結論出爐後收到通知,請聯繫support@ironsoftware.com。