I browsed a lot of instances and couldn't find a combination of these two requirements, because I could not save HTML as PDF but throw the stream at the same time, let's make a contribution ~~
Next we will select a web page to print, save as PDF, and implement stream throw and save. Suppose we choose"Http://www.cnblogs.com/ITGirl00/"
Page example:
string fileName = Guid.NewGuid().ToString();
string outputPath = Server.MapPath("output");
String savepath = string. Format (outputPath + "\" + fileName + ". pdf"); // save
string url = "http://www.cnblogs.com/ITGirl00/";
try
{
if (!string.IsNullOrEmpty(url) || !string.IsNullOrEmpty(savepath))
{
Process p = new Process();
string resource = HttpContext.Current.Server.MapPath("resoure");
string dllstr = string.Format(resource + "\\wkhtmltopdf.exe");
if (System.IO.File.Exists(dllstr))
{
p.StartInfo.FileName = dllstr;
p.StartInfo.Arguments = " \"" + url + "\" \"" + savepath + "\"";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
try
{
FileStream fs = new FileStream(savepath, FileMode.Open);
byte[] file = new byte[fs.Length];
fs.Read(file, 0, file.Length);
fs.Close();
Response.Clear();
Response. AddHeader ("content-disposition", "attachment; filename =" + fileName + ". pdf"); // encode
Response.ContentType = "application/octet-stream";
Response.BinaryWrite(file);
}
catch (Exception ee)
{
throw new Exception(ee.ToString());
}
}
}
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
Technorati tags: wkhtmtopdf, HTMLTOPDF, HTML conversion PDF, and outputStream