Search code examples
asp.netpdfwkhtmltopdfpdf-conversion

wkhtmltopdf creating empty pdf


I am using wkhtmltopdfto convert HTML page to PDF in ASP.NET. The following is my coding

protected void Button_Click(object sender, EventArgs e)
{
    Process p = new Process();
    p.StartInfo = new ProcessStartInfo();
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.FileName = Server.MapPath("~/wkhtmltopdf/wkhtmltopdf.exe");
    string arguments = "\"" + "http://localhost:51528/settings/InvoiceStatementPrint.aspx?InvoiceID=48\"" + " " + Server.MapPath("~/settings/" + "InvoiceDetail_1.pdf");
    p.StartInfo.Arguments = arguments;
    p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    p.StartInfo.CreateNoWindow = true;
    p.Start();
    p.WaitForExit();
    p.Close();
    p.Dispose();
}

The URL creates proper page. But InvoiceDetail_1.pdf generates black page PDF. Is there is any thing wrong in my code?


Solution

  • There is nothing wrong with your code, the problem will be with your input HTML. Try running the tool standalone and you'll see the same results.

    As an aside, TuesPechkin provides an easier way of calling wkhtmltopdf from .NET.