6

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>

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);

ご覧のとおり、html と wkhtmltopdf で utf-8 エンコーディングを引数として使用していますが、文字が正しくレンダリングされません。私は何が欠けていますか?以下は私がpdfで得たものです。英字は正常にレンダリングされます。

これは画像としてのpdfです

4

1 に答える 1

13

リダイレクトされたストリームの既定のエンコードは、既定のコード ページによって定義されます。UTF-8 に設定する必要があります。

残念ながらProcess、これを行うことはできないため、独自に作成する必要がありますStreamWriter

StreamWriter stdin = new StreamWriter(process.StandardInput.BaseStream, Encoding.UTF8);
于 2012-12-27T16:28:41.973 に答える