How to convert a page to PDF

Source: Internet
Author: User
Tags wkhtmltopdf

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.