I am using wkhtmltopdf to convert html to pdf. The issues are fonts with charaters like č,š,ž,đ (those are charaters used by Serbian, Croatian, Slovenian language). They are not displayed coretly in pdf. Html renders correctly.
This is how my html is constructed:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Export</title>
</head>
<body>
<h3>č,š,ž,đ</h3>
</body>
</html>
In my C# code where I am using wkhtmptopdf i do this
Process p;
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = HtmlToPdfExePath;
psi.WorkingDirectory = Path.GetDirectoryName(psi.FileName);
// run the conversion utility
psi.UseShellExecute = false;
psi.CreateNoWindow = true;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
// note: that we tell wkhtmltopdf to be quiet and not run scripts
string args = "-q -n ";
args += "--disable-smart-shrinking ";
args += "--orientation Portrait ";
args += "--outline-depth 0 ";
args += "--page-size A4 ";
args += "--encoding utf-8";
args += " - -";
psi.Arguments = args;
p = Process.Start(psi);
So as you can see I am using utf-8 encoding on html and wkhtmltopdf as argument but the charaters do not render corectly. What am I missing? Below is what i get in pdf. English characters renders normaly.
The default encoding for redirected streams is defined by your default code page. You need to set it to UTF-8.
Unfortunately Process
doesn't let you do this, so you need to make your own StreamWriter
:
StreamWriter stdin = new StreamWriter(process.StandardInput.BaseStream, Encoding.UTF8);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With