【问题标题】:How to implement "--print-media-type" with c#?如何用 c# 实现“--print-media-type”?
【发布时间】:2013-05-07 06:47:43
【问题描述】:

我目前正在使用带有 c# 的 wkhtmltopdf 将我的网页下载为 PDF 格式。但是,我希望生成的 PDF 显示为使用“print.css”。

其他细节: 我正在使用 Microsoft Visual Studio 2010。

这是我的代码:

protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
    string args = string.Format("\"{0}\" - ", Request.Url.AbsoluteUri);
    var startInfo = new ProcessStartInfo(Server.MapPath("~/wkhtmltoPDF/") + "wkhtmltopdf.exe", args)
    {
        UseShellExecute = false,
        RedirectStandardOutput = true
    };

    var proc = new Process { StartInfo = startInfo };
    proc.Start();

    Response.AddHeader("Content-Disposition", string.Format("attachment;filename=StaffDetails.pdf", Guid.NewGuid()));
    Response.AddHeader("Content-Type", "application/pdf"); string output = proc.StandardOutput.ReadToEnd();
    byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output);
    proc.Close();
    Response.BinaryWrite(buffer);
    }
}

【问题讨论】:

    标签: c# asp.net pdf-generation wkhtmltopdf


    【解决方案1】:

    只需将其添加为参数。尝试类似

    string args = string.Format("--print-media-type \"{0}\" - ", Request.Url.AbsoluteUri);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-10-11
      • 2017-10-01
      • 2018-02-15
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多