Thursday, 15 November 2012

Export Entire Website to PDF


Export Entire Website to PDF


1. You must have to download  wkhtmltopdf.exe from  http://code.google.com/p/wkhtmltopdf/

2. Place it where ever you feel confortable for execution like in Button Click Event.



string myDocumentsPath = "c:\\wkhtmltopdf.exe ";

ProcessStartInfo psi = new ProcessStartInfo(myDocumentsPath, " http://www.website.com/page");

psi.UseShellExecute = false;

psi.RedirectStandardOutput = true;

psi.RedirectStandardInput = true;

psi.RedirectStandardError = true;

psi.CreateNoWindow = true;

Process myProcess = Process.Start(psi);

myProcess.WaitForExit();

myProcess.Close();

Response.Clear();

Response.AddHeader("content-disposition", "attachment;filename=abc.pdf");

Response.ContentType = "application/pdf";

Response.WriteFile("D:\\bb.pdf");

Response.End();


Refer this link for more details:

http://www.dotnetobject.com/Thread-Weburl-to-PDF-conversion-in-asp-net

4 comments:

  1. Server Error in '/' Application.

    The system cannot find the file specified

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ComponentModel.Win32Exception: The system cannot find the file specified

    Source Error:


    Line 152: psi.RedirectStandardError = True
    Line 153: psi.CreateNoWindow = True
    Line 154: Dim myProcess As Process = Process.Start(psi)
    Line 155: myProcess.WaitForExit()
    Line 156: myProcess.Close()

    ReplyDelete
  2. Dear Madhu,

    IMHO, I guess you have not specified the complete path of either of wkhtmltopdf.exe or that of the page to be converted.. You have to give the complete path to get the desired result..

    For Example,

    string myDocumentsPath = "c:\\wkhtmltopdf.exe ";

    Here wkhtmltopdf.exe is in the C drive of your system.. Similarly you have to do that as well..

    Refer this:

    http://stackoverflow.com/questions/2369119/error-in-process-start-the-system-cannot-find-the-file-specified

    and

    http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx

    ReplyDelete
    Replies
    1. Protected Sub download1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Download1.Click
      Dim myDocumentsPath As String = "C:\wkhtmltopdf.exe "
      Dim info As New ProcessStartInfo("C:\Program Files\Internet Explorer\iexplore.exe")
      Dim psi As New ProcessStartInfo(myDocumentsPath, " http://www.yahoo.com")
      psi.UseShellExecute = False
      psi.RedirectStandardOutput = True
      psi.RedirectStandardInput = True
      psi.RedirectStandardError = True
      psi.CreateNoWindow = True

      Dim myProcess As Process = Process.Start(psi)
      myProcess.WaitForExit()
      myProcess.Close()
      Response.Clear()
      Response.AddHeader("content-disposition", "attachment;filename=abc.pdf")
      Response.ContentType = "application/pdf"
      Dim FilePath As String = MapPath("~/PDF/abc.pdf")
      Response.Write(FilePath)
      Response.[End]()
      above code i m using to convert page to pdf.........but downloaded folder is not opening getting error not decoded properly so not bale to open it

      Delete
    2. It seems like the error is related to the software itself...

      You can log the error over here:

      http://code.google.com/p/wkhtmltopdf/issues/list

      http://code.google.com/p/wkhtmltopdf/issues/list?can=1&q=&colspec=ID+Type+Status+Priority+Milestone+Owner+Summary&groupby=&sort=&x=&y=&cells=tiles&mode=grid

      Also Try to Use Different Version of wkhtmltopdf

      Moreover You could refer these links for some help:

      http://stackoverflow.com/questions/1331926/calling-wkhtmltopdf-to-generate-pdf-from-html/1698839#1698839

      http://stackoverflow.com/questions/2791981/how-to-use-wkhtmltopdf-exe-in-asp-net

      Delete

Thank You for Your Comments. We will get back to you soon.

back to top