Unicode Example

ABCpdf .net

 
   

This example shows how to add complex scripts such as Chinese, Japanese and Korean. Here we choose to embed and subset our font to ensure our document renders correctly on all platforms.

 

   
Setup  

First we create an ABCpdf Doc object and set the font size.

[C#]
Doc theDoc = new Doc();
theDoc.FontSize = 32;

[Visual Basic]
Dim theDoc As Doc = New Doc()
theDoc.FontSize = 32

 

   

Read
 

We read in our Japanese text from a Unicode text file.

[C#]
string thePath = Server.MapPath("../Rez/Japanese2.txt");
// Utilities.ReadString is an external function not defined here
string theText = Utilities.ReadString(thePath);

[Visual Basic]
Dim thePath As String = Server.MapPath("../Rez/Japanese2.txt")
' Utilities.ReadString is an external function not defined here
Dim theText As String = Utilities.ReadString(thePath)

 

   

Add
 

Because we want to ensure that our document renders correctly on all platforms we're going to embed our font in Unicode format. We specify a left-to-right writing direction and we choose to subset our font.

Please note when embedding fonts you must ensure you have permission to embed and redistribute the embedded font as part of your PDF.

[C#]
theDoc.Page = theDoc.AddPage();
theDoc.Font = theDoc.EmbedFont("MS PGothic", LanguageType.Unicode, false, true);
theDoc.AddText("Japanese" + theText);

[Visual Basic]
theDoc.Page = theDoc.AddPage()
theDoc.Font = theDoc.EmbedFont("MS PGothic", LanguageType.Unicode, False, True)
theDoc.AddText("Japanese" + theText)

 

   

Add
 

Just to show how it works we'll also render a page in vertical writing mode.

[C#]
theDoc.Page = theDoc.AddPage();
theDoc.Font = theDoc.EmbedFont("MS PGothic", LanguageType.Unicode, true, true);
theDoc.AddText("Japanese" + theText);

[Visual Basic]
theDoc.Page = theDoc.AddPage()
theDoc.Font = theDoc.EmbedFont("MS PGothic", LanguageType.Unicode, True, True)
theDoc.AddText("Japanese" + theText)

 

   

Save
 

Finally we save at a specified location.

[C#]
theDoc.Save(Server.MapPath("unicode.pdf"));
// finished

[Visual Basic]
theDoc.Save(Server.MapPath("unicode.pdf"))
' finished

 

   

Results
 

We get the following output.


unicode.pdf - [Page 1]

unicode.pdf - [Page 2]