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
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..