WkHtmlToPDF - How to write Korean Characters in downloaded PDF file with C#?

StackOverflow https://stackoverflow.com/questions/19976835

  •  30-07-2022
  •  | 
  •  

Question

I am trying to generate a PDF from HTML using wkhtmltopdf. It generates a PDF but it's not not showing korean language characters. How can I print korean or any other language characters in generated PDF?

I am using Response.write(PDFDataBytes) to download the PDF File as below:

Response.Clear();
Response.Cache.SetCacheability(HttpCacheability.Private);
Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf");
Response.ContentType = "application/octet-stream;charset=utf-8";    
Response.BinaryWrite(Byte_dat_to_Generate_PDF);
Response.Flush();
Response.End();
Était-ce utile?

La solution 2

There was just lake of following tag in HTML page:

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

now working......

Autres conseils

One thing to notice other than making everything everywhere UTF-8 is that if you are generating the PDF in a server, the server must also have the correct fonts installed. The server renders the page using available fonts, so if it can't display Hangeul characters, it can't render the PDF correctly.

PDF doesn't use the fonts in the client like HTML does, the fonts are often embedded inside the PDF file.

I have a setup like this where everything is UTF-8 and the fonts are installed and wkhtmltopdf behaves just nicely.

By outputting the HTML with the proper encoding headers. You can also specify the --encoding command line parameter.

I've resolved this issue on Ubuntu 11.10(server) by copying the /usr/share/fonts from Ubuntu 14.04 LS (desktop) and then running a command:

sudo fc-cache -f -v

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top