【问题标题】:Convert Html to PDF using wkhtmltopdf使用 wkhtmltopdf 将 Html 转换为 PDF
【发布时间】:2014-03-17 11:18:18
【问题描述】:

我正在使用 wkhtmltopdf 将页面转换为 pdf,但是当我想通过用户名和密码转换受保护的页面时,站点将 url 重定向到另一个请求用户名和密码的页面,尽管用户已经登录。

转换的方法使用进程var p = new System.Diagnostics.Process() { StartInfo = { FileName = pdfHtmlToPdfExePath, Arguments = ((options == null) ? "" : String.Join(" ", options)) + " " + urlsSeparatedBySpaces + " " + outputFilename, UseShellExecute = false, // needs to be false in order to redirect output RedirectStandardOutput = true, RedirectStandardError = true, RedirectStandardInput = false, // redirect all 3, as it should be all 3 or none WorkingDirectory = HttpContext.Current.Server.MapPath(outputFolder) } };

有人知道如何解决这个问题吗?

【问题讨论】:

  • 你现在有工作版本吗?
  • @Dhara 我得到了这个工作,但几年前我离开了这个项目,很抱歉我没有解决方案。
  • 哦!不是问题:) @Fakhry

标签: pdf wkhtmltopdf


【解决方案1】:

关于文档 (http://wkhtmltopdf.org/usage/wkhtmltopdf.txt),您应该能够将 cookie 作为参数传递。

在启动外部进程之前尝试使用如下代码,然后您作为用户发送到服务器的 cookie 应该包含在请求中。

foreach(var cookie in System.Web.HttpContext.Current.Request.Cookies)
{
    options += string.Format(" --cookie {0} {1}", cookie.Name, cookie.Value)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 1970-01-01
    • 1970-01-01
    • 2013-03-19
    • 2017-12-24
    相关资源
    最近更新 更多