wkhtmltopdf.exe System.Security.SecurityException on cloud web server. How can i override server security policy

后端 未结 1 365
情话喂你
情话喂你 2021-01-06 10:08

I want to have a feature for my website which can print the page contents as PDF. I tried a few option for this but the best match was wkhtmltopdf as it also handle multilin

相关标签:
1条回答
  • 2021-01-06 11:01

    WORKING CODE: I resolved the issue by calling the PrintArticle.aspx from MainPage.aspx, When user clinks on the lnkbtnDownload link Button it will call the page PrinteArticle.aspx (Print Article Page is a simple page which show article title, date and Article Description) and pass the HTML to the code below which will then print it as a PDF file

       protected void lnkbtnDownload_Click(object sender, EventArgs e)
        {
            string url = "PrintArticle.aspx?articleID=" + Request["articleID"] + "&download=yes&Language=" + Request["Language"];
    
            string args = string.Format("\"{0}\" - ", "http://xyz.net/" + url);
            var startInfo = new ProcessStartInfo(Server.MapPath("bin\\wkhtmltopdf.exe"), args)
            {
                UseShellExecute = false,
                CreateNoWindow = true,
                RedirectStandardOutput = true
    
            };
            var proc = new Process { StartInfo = startInfo };
            proc.Start();
    
            string output = proc.StandardOutput.ReadToEnd();
            byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output);
            proc.WaitForExit();
            proc.Close();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition", "attachment;filename=download.pdf");
            Response.BinaryWrite(buffer);
            Response.End();
        }
    

    I am passing other parameters as query string like articleID, Download, Language etc..

    0 讨论(0)
提交回复
热议问题