How to Use UTF-8 Encoding and International Languages in PDFs

IronPDF supports UTF-8 Encoding in PDFs because it complies with the Chrome standard. Any character that can be rendered properly within a Chrome browser will be supported by IronPDF. You can be assured that foreign languages will have their characters rendered properly. In this How-To, we will step through how you can render UTF-8 in a PDF.

Get started with IronPDF

Start using IronPDF in your project today with a free trial.

First Step:
green arrow pointer




Simple Code Example

When working with IronPDF, we often use extended character sets such as UTF-8 Encoding.

Here we have an example of the string being passed into the RenderHtmlAsPdf method, which expects an HTML string input:

string htmlContent = @"
    <p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
    文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
    失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
    陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>

    <p>أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملا المنتصر,
    ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
    زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.</p>

    <p>ภคนทลาพาธสตารเซฟต แชมป มารเกตตงลมเหลวโยเกรต แลนดบาบนอมครม รสโซ แบรนดไคลแมกซ พซซาโมเดลเสอโครง มอบโซนรายชอ
    แอดมชชน ดอกเตอร พะเรอ มารคเจไดโมจราสเบอรร เอนทรานซออดชนศลปวฒนธรรมเปราะบาง โมจซเรยสวอลนตทรปลเมอร ทป วาไรตบกเมเปล</p>
";
string htmlContent = @"
    <p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
    文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
    失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
    陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>

    <p>أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملا المنتصر,
    ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
    زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.</p>

    <p>ภคนทลาพาธสตารเซฟต แชมป มารเกตตงลมเหลวโยเกรต แลนดบาบนอมครม รสโซ แบรนดไคลแมกซ พซซาโมเดลเสอโครง มอบโซนรายชอ
    แอดมชชน ดอกเตอร พะเรอ มารคเจไดโมจราสเบอรร เอนทรานซออดชนศลปวฒนธรรมเปราะบาง โมจซเรยสวอลนตทรปลเมอร ทป วาไรตบกเมเปล</p>
";
Dim htmlContent As String = "
    <p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
    文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
    失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
    陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>

    <p>أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملا المنتصر,
    ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
    زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.</p>

    <p>ภคนทลาพาธสตารเซฟต แชมป มารเกตตงลมเหลวโยเกรต แลนดบาบนอมครม รสโซ แบรนดไคลแมกซ พซซาโมเดลเสอโครง มอบโซนรายชอ
    แอดมชชน ดอกเตอร พะเรอ มารคเจไดโมจราสเบอรร เอนทรานซออดชนศลปวฒนธรรมเปราะบาง โมจซเรยสวอลนตทรปลเมอร ทป วาไรตบกเมเปล</p>
"
$vbLabelText   $csharpLabel

The above text is wrapped in <p> tags because we're dealing with an HTML string. You can pass this HTML string to IronPDF's Chrome PDF Renderer using methods like RenderHtmlAsPdf.

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

const string html_with_utf_8 =
    @"<p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
    文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
    失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
    陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>
    <p>
    أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملا المنتصر,
    ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
    زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.
    </p>
    <p>
    ภคนทลาพาธสตารเซฟต แชมป มารเกตตงลมเหลวโยเกรต แลนดบาบนอมครม รสโซ แบรนดไคลแมกซ พซซาโมเดลเสอโครง มอบโซนรายชอ
    แอดมชชน ดอกเตอร พะเรอ มารคเจไดโมจราสเบอรร เอนทรานซออดชนศลปวฒนธรรมเปราะบาง โมจซเรยสวอลนตทรปลเมอร ทป วาไรตบกเมเปล
    </p>";

var renderer = new ChromePdfRenderer();
renderer.RenderingOptions.InputEncoding = System.Text.Encoding.UTF8;

var pdf = renderer.RenderHtmlAsPdf(html_with_utf_8);
pdf.SaveAs("Unicode.pdf");
Imports IronPdf

Private Const html_with_utf_8 As String = "<p>周態告応立待太記行神正用真最。音日独素円政進任見引際初携食。更火識将回興継時億断保媛全職。
    文造画念響竹都務済約記求生街東。天体無適立年保輪動元念足総地作靖権瀬内。
    失文意芸野画美暮実刊切心。感変動技実視高療試意写表重車棟性作家薄井。
    陸瓶右覧撃稿法真勤振局夘決。任堀記文市物第前兜純響限。囲石整成先尾未展退幹販山令手北結。</p>
    <p>
    أم يذكر النفط قبضتهم على, الصين وفنلندا ما حدى. تم لكل أملا المنتصر,
    ٣٠ حدى مارد القوى. شرسة للسيطرة قامفي. حتى أم يطول المحيط,
    زهاء وحلفاؤها من فعل. لم قامت الجو الساحلية وتم, ويعزى واقتصار قبل كل.
    </p>
    <p>
    ภคนทลาพาธสตารเซฟต แชมป มารเกตตงลมเหลวโยเกรต แลนดบาบนอมครม รสโซ แบรนดไคลแมกซ พซซาโมเดลเสอโครง มอบโซนรายชอ
    แอดมชชน ดอกเตอร พะเรอ มารคเจไดโมจราสเบอรร เอนทรานซออดชนศลปวฒนธรรมเปราะบาง โมจซเรยสวอลนตทรปลเมอร ทป วาไรตบกเมเปล
    </p>"

Private renderer = New ChromePdfRenderer()
renderer.RenderingOptions.InputEncoding = System.Text.Encoding.UTF8

Dim pdf = renderer.RenderHtmlAsPdf(html_with_utf_8)
pdf.SaveAs("Unicode.pdf")
$vbLabelText   $csharpLabel

This is the file that the code produced:

To ensure you get perfect encoding of your HTML as a PDF, specify your desired charset in two places:

  • In ChromePdfRenderer.RenderingOptions using System.Text.Encoding.UTF8
  • In your HTML Header:
<html>
    <head>
        <meta charset='utf-8'>
    </head>
    <body>
        こんにちは世界
    </body>
</html>
<html>
    <head>
        <meta charset='utf-8'>
    </head>
    <body>
        こんにちは世界
    </body>
</html>
HTML

More about International Languages

IronPDF supports HTML-To-PDF in non-Latin script languages, including Chinese, Japanese, Arabic, Hebrew, Russian, Thai, and all international languages supported by Unicode, including mixed language documents.

There are two things to consider when working with international languages:

Typefaces

A typeface that supports your character set must be installed on your server. These are normally automatically installed on modern web servers, but older servers may have been installed with older versions of some fonts such as Arial, which may not have full UTF-8 support.

An alternative solution is to specify a Web Font in your CSS, such as those provided by Google Fonts. More information can be found in the article How to Use Google Fonts in Your Next Web Design Project.

Input Encoding

You may have to specify the input encoding of your document to render correctly. You may do this in the following ways:

Adding an HTML "Meta Charset" Tag e.g.

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
HTML

Ready to see what else you can do? Check out our tutorial page here: Addtional Features

Frequently Asked Questions

How can I create a PDF with UTF-8 encoding in C#?

To create a PDF with UTF-8 encoding in C#, use IronPDF's RenderHtmlAsPdf method. First, ensure that your HTML content includes UTF-8 encoded characters, then set the InputEncoding property to UTF8 before rendering.

Why is UTF-8 important when generating PDFs?

UTF-8 is crucial for PDF generation because it supports all Unicode characters, ensuring accurate rendering of international and special characters. IronPDF utilizes UTF-8 to comply with modern web standards, making it suitable for diverse language support.

What are the typical challenges with UTF-8 PDF generation?

Common challenges include ensuring proper character rendering for non-Latin scripts and managing fonts that support diverse character sets. IronPDF addresses these by allowing the use of web fonts like Google Fonts and setting the correct charset in the HTML.

How do I render non-Latin scripts in a PDF using C#?

To render non-Latin scripts in a PDF using C#, use IronPDF. Make sure your HTML content includes the necessary character set and specify a compatible web font if needed. IronPDF will handle the rendering of scripts like Chinese, Japanese, or Arabic.

What steps should I follow to ensure correct UTF-8 encoding in my PDFs?

To ensure correct UTF-8 encoding in PDFs, use IronPDF and include a meta charset="UTF-8" tag in your HTML. Set the ChromePdfRenderer.RenderingOptions.InputEncoding to UTF8 as well.

How can I troubleshoot encoding issues in PDFs generated using C#?

If you encounter encoding issues, check that your HTML includes a meta charset="UTF-8" tag and that you're using fonts that support your characters. IronPDF allows you to specify these settings to resolve encoding problems.

Can I use Google Fonts to improve international language support in PDFs?

Yes, Google Fonts can be used to improve international language support in PDFs. With IronPDF, you can specify these web fonts in your HTML, ensuring that all characters are displayed correctly in the generated PDF.

What is the role of the 'Meta Charset' tag in PDF generation?

The 'Meta Charset' tag defines the character encoding for your HTML content, which is crucial for rendering text correctly in PDFs. IronPDF uses this tag to ensure that UTF-8 encoded characters are processed accurately.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.