CMYK 與國際語言 PDF 的疑難排解

This article was translated from English: Does it need improvement?
Translated
View the article in English

IronPDF 支援 Unicode 所涵蓋的所有國際語言的 HTML 轉 PDF 功能,包括混合語言文件。

有兩點需特別留意:字型輸入編碼,相關詳情請參閱此常見問題頁面: https://ironpdf.com/how-to/utf-8/

您的伺服器上必須安裝支援該字元集的字型。

您可能需要指定文件的輸入編碼,才能正確顯示內容。

您可以透過以下方式達成此目標:

  1. 新增 HTML"Meta Charset"標籤

    此方法需在 HTML 的 <head> 區段中加入 <meta> 標籤,以定義字元集。 這可確保您的 HTML 文件使用正確的字元。

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Your Document Title</title>
    </head>
    <body>
        <p>Your document content goes here...</p>
    </body>
    </html>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Your Document Title</title>
    </head>
    <body>
        <p>Your document content goes here...</p>
    </body>
    </html>
    HTML

    <meta charset="UTF-8"> 標籤指定了 UTF-8 字元編碼,該編碼可處理任何 Unicode 字元。

  2. 設定 IronPDF HTML 轉 PDF 轉換器的 inputEncoding 屬性

    您可以設定 IronPDF 轉換器的 inputEncoding 屬性,藉此在轉換過程中指定字元編碼。

    您可以在 C# 程式碼中透過以下方式實現:

    using IronPdf;
    
    class Program
    {
        static void Main()
        {
            // Instantiate a renderer
            var Renderer = new HtmlToPdf
            {
                // Set the input encoding to UTF-8
                RenderOptions = new ChromePdfRendererOptions
                {
                    InputEncoding = "UTF-8"
                }
            };
    
            // Convert HTML to PDF
            var PDF = Renderer.RenderHtmlAsPdf("<p>Sample content with UTF-8 encoding</p>");
    
            // Save the PDF to disk
            PDF.SaveAs("output.pdf");
        }
    }
    using IronPdf;
    
    class Program
    {
        static void Main()
        {
            // Instantiate a renderer
            var Renderer = new HtmlToPdf
            {
                // Set the input encoding to UTF-8
                RenderOptions = new ChromePdfRendererOptions
                {
                    InputEncoding = "UTF-8"
                }
            };
    
            // Convert HTML to PDF
            var PDF = Renderer.RenderHtmlAsPdf("<p>Sample content with UTF-8 encoding</p>");
    
            // Save the PDF to disk
            PDF.SaveAs("output.pdf");
        }
    }
    Imports IronPdf
    
    Friend Class Program
    	Shared Sub Main()
    		' Instantiate a renderer
    		Dim Renderer = New HtmlToPdf With {
    			.RenderOptions = New ChromePdfRendererOptions With {.InputEncoding = "UTF-8"}
    		}
    
    		' Convert HTML to PDF
    		Dim PDF = Renderer.RenderHtmlAsPdf("<p>Sample content with UTF-8 encoding</p>")
    
    		' Save the PDF to disk
    		PDF.SaveAs("output.pdf")
    	End Sub
    End Class
    $vbLabelText   $csharpLabel
    • HtmlToPdf:這是 IronPDF 函式庫中的一種類別,用於將 HTML 文件轉換為 PDF。
    • RenderOptions.InputEncoding:此屬性可讓您設定輸入資料的編碼。 此處設定為 "UTF-8" 以支援國際化語言。
    • RenderHtmlAsPdf:此方法將指定的 HTML 內容渲染為 PDF 格式。
    • SaveAs:此方法用於將渲染後的 PDF 檔案儲存至指定的檔案路徑。

請參閱 IronPDF 文件中關於 inputEncoding 屬性的詳細說明:IronPdf.ChromePdfRenderOptions.inputEncoding

Curtis Chau
技術撰稿人

Curtis Chau 擁有卡爾頓大學(Carleton University)的電腦科學學士學位,專精於前端開發,並精通 Node.js、TypeScript、JavaScript 及 React。他熱衷於打造直觀且美觀的用戶介面,喜歡運用現代框架,並創建結構完善、視覺上吸引人的手冊。

除了開發工作之外,Curtis 對物聯網(IoT)抱有濃厚興趣,致力於探索整合硬體與軟體的創新方法。閒暇時,他喜歡玩遊戲和開發 Discord 機器人,將對科技的熱愛與創意相結合。

準備開始了嗎?
Nuget 下載 19,014,616 | 版本: 2026.5 just released
Still Scrolling Icon

還在往下捲動嗎?

想要快速確認成果嗎? PM > Install-Package IronPdf
執行範例 觀看您的 HTML 轉為 PDF。