C#mvc 4中的Wkhtmltopdf编码问题

The*_*tor 6 c# wkhtmltopdf asp.net-mvc-4

我使用wkhtmltopdf将html转换为pdf.这些问题是字体,如č,š,ž,đ(这些是塞尔维亚语,克罗地亚语,斯洛文尼亚语使用的字符).它们不会以pdf格式显示.Html渲染正确.

这就是我的html构造方式:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Export</title>
</head>
<body>
    <h3>?,š,ž,?</h3>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

在我使用wkhtmptopdf的C#代码中,我这样做

        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);
Run Code Online (Sandbox Code Playgroud)

所以你可以看到我在html和wkhtmltopdf上使用utf-8编码作为参数,但是字符不会呈现出核心.我错过了什么?以下是我在pdf中获得的内容.英文字符呈现正常.

这是pdf作为图像

Cor*_*son 13

重定向流的默认编码由您的默认代码页定义.您需要将其设置为UTF-8.

不幸的是Process不允许你这样做,所以你需要自己做StreamWriter:

StreamWriter stdin = new StreamWriter(process.StandardInput.BaseStream, Encoding.UTF8);
Run Code Online (Sandbox Code Playgroud)