1. Implement code to convert HTML to PDF is mainly generated using the Wkhtmltopdf.exe tool, in the acquisition of the address of the conversion, create a process, the address passed to the process parameters to call the Wkhtmltopdf.exe tool printing
2. Code Snippet//Call tool section
//<summary> //Start wkhtmltopdf //</summary> //< param name= "parms" > Startup Parameters </param> //<returns></ returns> public void Startwk (string parms, bool Isnohead = True) & nbsp; { Try { Process proc = new process (); string resource = HttpContext.Current.Server.MapPath ("~/content/wkhtmltopdf/bin"); string dllstr = string. Format (Resource + "\\wkhtmltopdf.exe");
if ( System.IO.File.Exists (DLLSTR)) { Proc. Startinfo.filename = Dllstr; String strarguments = Isnohead? String. Empty: "--margin-top--margin-bottom--header-spacing 2--footer-spacing 1--footer-font-size 7--footer-center \" Section [Page] Page/total [topage] page \ ""; Strarguments + = parms;
Proc. Startinfo.arguments = strarguments; Proc. Startinfo.useshellexecute = false; Proc. Startinfo.redirectstandardinput = true; Proc. Startinfo.redirectstandardoutput = true; Proc. Startinfo.redirectstandarderror = true; Proc. Startinfo.createnowindow = true; Proc. Start (); Proc. WaitForExit (); } Else { throw new Exception ("Wkhtmltopdf.exe start exception! "); } } catch (Exception) { throw; } }
How to convert a page to PDF