2012-10-11 14 views
3

我想將HTML頁面轉換爲PDF。有幾種選擇,但他們有一些問題。在IE將HTML轉換爲PDF的正確方法

  • 打印HTML頁面通過PDFCreator(太麻煩)
  • 使用wkhtmltopdf(低質量)
  • 使用PhantomJS(低質量)

也許我可以用一個複雜的解決方案?要使用PhantomJSPDFCreator進行打印,還是要提高wkhtmltopdf的質量,或者其他方法?

+0

你能告訴你正在使用的wkhtmltopdf的版本嗎? – pomaxa

+0

版本0.11.0 rc2 – ChruS

+0

你試過0.9版本(最後一個穩定版本)嗎?因爲我沒有任何質量問題。 – pomaxa

回答

0

也許你可以試試Amyuni WebkitPDF。它不是開源的,但它可以免費用於商業用途,它可以在C#中使用。從文檔的C#

示例代碼:

static private void SaveToFile(string url, string file) 
{   
    // Store the WebkitPDFContext returned value in an IntPtr 
    IntPtr context = IntPtr.Zero; 
    // Open the URL. The WebkitPDFContext returned value will be stored in 
    // the passed in IntPtr 
    int ret = WKPDFOpenURL(url, out context, 0, false); 
    if (ret == 0) 
    { 
     // if ret is 0, then we succeeded in opening the URL. 
     // Save the result as PDF to a file. Use the obtained context value 
     ret = WKPDFSaveToFile(file, context); 
    } 
    if (ret != 0) 
     Debug.WriteLine("Failed to run SaveToFile on '" + url + "' to generate file '" + file + "'"); 
    // Make sure to close the WebkitPDFContext because otherwise the 
    // internal PDFCreator as well as other objects will not be released 
    WKPDFCloseContext(context); 
} 

平時免責聲明適用