2

我正在使用 wkhtmltopdf 应用程序将我的 ASP.net MVC 2 呈现的 HTML 转换为 PDF 并显示 PDF 而不是标准视图,以获得更好的打印能力。减去一件事,一切都很好。当我在 Web 服务器上的 MVC 应用程序中将 wkhtmltopdf 作为进程运行时,它不会在 PDF 中显示已安装的条形码字体。

这是该过程的代码。

public void HtmlToPdf(string url, string appPath)
    {

        string message = null;
        // to build command argument
        StringBuilder argument = new StringBuilder();
        // input html file
        string switches = "";
        switches += "--print-media-type ";
        switches += "--margin-top 10mm --margin-bottom 10mm --margin-right 10mm --margin-left 10mm ";
        switches += "--page-size Letter ";
        switches += "--load-error-handling ignore ";
        switches += "--username admin ";
        switches += "--password pass ";
        argument.Append(switches + " " + url + " " + "C:\\PDF\\temp.pdf");


        // to call the exe to convert

        System.Diagnostics.Process p = new System.Diagnostics.Process();
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = true;

        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.RedirectStandardError = true;
        p.StartInfo.FileName = "C:\\wkhtmltopdf\\wkhtmltopdf.exe";
        p.StartInfo.WorkingDirectory = "C:\\wkhtmltopdf";
        p.StartInfo.Arguments = argument.ToString();

        p.Start();
        p.WaitForExit();
        message = p.StandardError.ReadToEnd();

        if (string.IsNullOrEmpty(message))
        {
            message = p.StandardOutput.ReadToEnd();
        }
        else
        {
            System.Diagnostics.Debug.WriteLine(message);
        }
    }

不太确定为什么它不会显示条形码,因为它会在您呈现 html 时显示,但不会在 wkhtmltopdf 将其转换为 pdf 时显示。如果您在我的 MVC 应用程序之外运行 wkhtmltopdf,它也可以正常工作。

-谢谢你的帮助

4

1 回答 1

0

您是否曾尝试过使用更新版本的 wkhtmltopdf?

这是哪个版本的问题?我最近尝试使用我下载的随机字体生成并且效果很好。

如果您在服务器上生成 PDF,服务器也需要该字体,我假设您知道这一点,但其他阅读者可能没有意识到 :) 我可以让有问题的字体在我的系统上进行测试吗?转换是在什么环境下进行的?(由于asp.net,很可能不是Linux,但以防万一)

于 2012-08-16T16:38:35.207 回答