//PDF File Export PublicActionResult PDFs () {//path to the exported page (dead path) stringURL ="http://localhost:1213/"; //the path of the plugin (converted to Pdfne) stringPDF ="C:/Program Files/wkhtmltopdf/bin/wkhtmltopdf.exe"; //randomly generate a file name stringfilename =Guid.NewGuid (). ToString (); //PDF Format stringPdfpath = filename +". pdf"; Process P= System.Diagnostics.Process.Start (pdf, URL +" \""+ Server.MapPath (Pdfpath) +"\""); p.WaitForExit (); //DownloadFileStream fs =NewFileStream (Server.MapPath (Pdfpath), 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");//forced download in binary streaming modeResponse.ContentType ="Application/octet-stream"; Response.BinaryWrite (file); Response.Write ("<script>window.location= ' index.cshtml ' </script>"); return NULL; }
//jpg file Export PublicActionResult JPGs () {//path of the exported page stringURL ="http://localhost:1213/"; //the path of the plugin (converted to JPG) stringJPG ="C:/Program Files/wkhtmltopdf/bin/wkhtmltoimage.exe"; //randomly generate a file name stringfilename =Guid.NewGuid (). ToString (); //jpg format stringPdfpath = filename +". jpg"; Process P= System.Diagnostics.Process.Start (jpg, url +" \""+ Server.MapPath (Pdfpath) +"\""); p.WaitForExit (); //DownloadFileStream fs =NewFileStream (Server.MapPath (Pdfpath), 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 +". jpg");//forced download in binary streaming modeResponse.ContentType ="Application/octet-stream"; Response.BinaryWrite (file); Response.Write ("<script>window.location= ' index.cshtml ' </script>"); return NULL; }
Layout page code: <a> @Html. ActionLink (" current page export PDF""pdfs" ) </a> <a> @Html. ActionLink (" current page export jpg""jpgs ") </a>
Go to PDF, jpg plugin (wkhtmltox-0.12.4_msvc2015-win64.exe)
Asp. NET specify page to PDF, JPG (plugin)