Skip to content

956797 Added the TOC with Unicode Font while converting HTML to PDF. #164

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HtmlToPdfWithUnicodeTOC", "HtmlToPdfWithUnicodeTOC\HtmlToPdfWithUnicodeTOC.csproj", "{4AD65462-EECF-4D8A-82C1-8E4127CE70A3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4AD65462-EECF-4D8A-82C1-8E4127CE70A3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4AD65462-EECF-4D8A-82C1-8E4127CE70A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4AD65462-EECF-4D8A-82C1-8E4127CE70A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4AD65462-EECF-4D8A-82C1-8E4127CE70A3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Multilingual Sample Document</title>
<style>
body {
font-family: Arial, sans-serif;
line-height: 1.6;
padding: 20px;
}
h1, h2 {
color: #2c3e50;
}
ul.toc {
list-style-type: none;
padding-left: 0;
}
ul.toc li {
margin: 5px 0;
}
ul.toc a {
text-decoration: none;
color: #007BFF;
}
ul.toc a:hover {
text-decoration: underline;
}
</style>
</head>
<body>

<h1>Sample Document – Beispiel – Пример документа</h1>

<h2>Table of Contents – Inhaltsverzeichnis – Содержание</h2>
<ul class="toc">
<li><a href="#english">English</a></li>
<li><a href="#german">Deutsch (German)</a></li>
<li><a href="#russian">Русский (Russian)</a></li>
</ul>

<hr>

<h2 id="english">English Section</h2>
<p>This document demonstrates multilingual content in HTML using UTF-8 encoding. You can mix English, German, and Russian in the same page.</p>

<h2 id="german">Deutscher Abschnitt</h2>
<p>Dieses Dokument zeigt mehrsprachige Inhalte in HTML mit UTF-8-Kodierung. Sie können Englisch, Deutsch und Russisch auf derselben Seite verwenden.</p>
<ul>
<li>Zeichen wie ä, ö, ü, ß werden korrekt angezeigt.</li>
<li>Unterstützt auch deutsche Umlaute.</li>
</ul>

<h2 id="russian">Русский раздел</h2>
<p>Этот документ демонстрирует мультиязычное содержимое в HTML с использованием кодировки UTF-8. Вы можете использовать английский, немецкий и русский языки на одной странице.</p>
<ul>
<li>Кириллические символы отображаются правильно.</li>
<li>Полная поддержка русского алфавита.</li>
</ul>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.HtmlToPdfConverter.Net.Windows" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Syncfusion.Drawing;
using Syncfusion.HtmlConverter;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.HtmlToPdf;
using Syncfusion.Pdf;

// Initialize the HTML to PDF converter with Blink rendering engine
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.Blink);

// Create Blink converter settings
BlinkConverterSettings settings = new BlinkConverterSettings
{
EnableToc = true
};
using (FileStream fontStream = new FileStream(Path.GetFullPath(@"Data/ARIALUNI.TTF"), FileMode.Open, FileAccess.Read))
{
// Load a Unicode TrueType font from system or custom path
PdfTrueTypeFont unicodeFont = new PdfTrueTypeFont(fontStream, 14);

// Set the style for level 1 (H1) items in table of contents
HtmlToPdfTocStyle tocStyleH1 = new HtmlToPdfTocStyle
{
Font = unicodeFont,
BackgroundColor = new PdfSolidBrush(new PdfColor(Color.FromArgb(68, 114, 196))),
ForeColor = PdfBrushes.White,
Padding = new PdfPaddings(5, 5, 3, 3)
};

// Apply the style to TOC level 1
settings.Toc.SetItemStyle(1, tocStyleH1);

// Assign Blink converter settings to HTML converter
htmlConverter.ConverterSettings = settings;

// Convert HTML to PDF
PdfDocument document = htmlConverter.Convert(Path.GetFullPath(@"Data/Input.html"));

// Save and close the PDF document
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Output/Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
document.Save(fileStream);
}
//Close the PDF document
document.Close(true);
}
Loading