2013-05-13 43 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);