Search code examples
c#pdfcjkdynamicpdf

PDF created by DynamicPDF renders korean text as blank


I am using DynamicPDF to generate a PDF file with some Korean text. I'm using the PDF system fonts for CJK characters and am not getting the dreaded squares, I'm just getting... blankness.

The characters take up space and adding latin characters afterwards do show up in the position you'd expect them. Selecting the blank space and right clicking or copying it shows the proper expected characters so they exist.

My system does render Korean text, showing it in a HTML page in chrome works while the PDF in chrome doesn't.

Here is a minimal sample with (working) Japanese text to compare.

Poor Korean text :(

ceTe.DynamicPDF.Document document = new ceTe.DynamicPDF.Document();
ceTe.DynamicPDF.Page page = new ceTe.DynamicPDF.Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);

// Create a Label to add to the page
var testString = "Korean: 안녕하세요 세계 </korean>";
page.Elements.Add(new Label(testString, 0, 0, 504, 100, Font.SinoTypeSongLight, 18, TextAlign.Center));
page.Elements.Add(new Label(testString, 0, 100, 504, 100, Font.HanyangSystemsGothicMedium, 18, TextAlign.Center));
page.Elements.Add(new Label(testString, 0, 200, 504, 100, Font.HanyangSystemsShinMyeongJoMedium, 18, TextAlign.Center));

testString = "Japan: こんにちは世界 </japan>";
page.Elements.Add(new Label(testString, 0, 300, 504, 100, Font.SinoTypeSongLight, 18, TextAlign.Center));

// Add page to document
document.Pages.Add(page);

// Outputs the document to the current web page
document.Draw("D:/HelloWorld.pdf");

Solution

  • Please refer to the DynamicPDF documentation on CJK fonts.

    SinoTypeSongLight font you are using to add Korean characters actually supports simplified Chinese language characters. There is no support for Korean character in that font so blank space is expected for the first line in the PDF.

    In the second and third lines you are actually using the correct fonts (HanyangSystemsGothicMedium & HanyangSystemsShinMyeongJoMedium) that support Korean characters. However, according to the documentation link above you should have the Asian Font Pack installed on the machine where you are viewing this PDF. I am not sure what PDF viewer plugin your Chrome browser uses but PDF viewers like Adobe Reader provide Asian Font Pack as an add-on. Please see the screenshot that shows the PDF generated with your code in Adobe Reader DC with Asian Font Pack.

    enter image description here

    Disclaimer: I work for ceTe Software, the company that develops DynamicPDF libraries.