2013-05-13 60 views
0

我目前使用wkhtmltopdf与c#来下载我的网页作为PDF格式。但是,我希望生成的PDF显示为使用“print.css”。如何用c#实现“--print-media-type”?

其他细节: 我使用Microsoft Visual Studio 2010

这是我的代码:

protected void ImageButton2_Click(object sender, ImageClickEventArgs e) 
{ 
    string args = string.Format("\"{0}\" - ", Request.Url.AbsoluteUri); 
    var startInfo = new ProcessStartInfo(Server.MapPath("~/wkhtmltoPDF/") + "wkhtmltopdf.exe", args) 
    { 
     UseShellExecute = false, 
     RedirectStandardOutput = true 
    }; 

    var proc = new Process { StartInfo = startInfo }; 
    proc.Start(); 

    Response.AddHeader("Content-Disposition", string.Format("attachment;filename=StaffDetails.pdf", Guid.NewGuid())); 
    Response.AddHeader("Content-Type", "application/pdf"); string output = proc.StandardOutput.ReadToEnd(); 
    byte[] buffer = proc.StandardOutput.CurrentEncoding.GetBytes(output); 
    proc.Close(); 
    Response.BinaryWrite(buffer); 
    } 
} 

回答

0

只需将其添加为一个参数。尝试类似

string args = string.Format("--print-media-type \"{0}\" - ", Request.Url.AbsoluteUri);