Generally, you can generate common features that do not require user and password verification. The following code is used to generate a PDF file for the pages based on Windows authentication (my work is based on SharePoint)
The Code is as follows:
Public bool htmltopdf (string URL, string path) {try {string filename = pdffolder + "\" + path + ". PDF "; process P = new system. diagnostics. process (); p. startinfo. filename = @ "C: \ pdffolder \ wkhtmltow..exe"; // P. startinfo. username = "Administrator"; // user name // P. startinfo. password = stringtosecurestring ("password01! "); // User Password // P. startinfo. arguments = "" + "\" "+ URL +" \ "" + "" + "\" "+ filename +" \ ""; p. startinfo. arguments = string. format ("\" {0} \ "\" {1} \ "-- password \" {2} \ "-- USERNAME \" {3} \ "", URL, filename, "[page Password]", "[user name for page logon]"); p. startinfo. useshellexecute = false; // needs to be false in order to redirect output p. startinfo. redirectstandardoutput = true; p. startinfo. redirectstandarderror = true; p. startinfo. redirectstandardinput = true; // redirect all 3, as it shoshould be all 3 or none p. startinfo. workingdirectory = "C: \ pdffolder"; p. start (); // read the output here... string output = P. standardoutput. readtoend ();//... then wait n milliseconds for exit (as after exit, it can't read the output) p. waitforexit (60000); // read the exit code, close process int returncode = P. exitcode; p. close (); // If 0 or 2, it worked (not sure about other values, I want a better way to confirm this) return (returncode = 0 | returncode = 2);} catch (exception ex) {} return false ;}
Public static securestring stringtosecurestring (string Str)
{
Securestring securestr = new securestring ();
Char [] chars = Str. tochararray ();
For (INT I = 0; I <chars. length; I ++)
{
Securestr. appendchar (chars [I]);
}
Return securestr;
}
The usage is as follows:
HtmlToPdf("http://www.baidu.com", "buidu1")
But there may be garbled issues, there may be two ways, first, in the code modification, but now because the project has no requirements, there is no research for the moment, the second, if it is your own page, you can modify the encoding method of the page.
You can download the wkhtmltocmd.exe file from the following network:
Http://files.cnblogs.com/gzh4455/wkhtmltopdf.zip