3
我想將HTML頁面轉換爲PDF。有幾種選擇,但他們有一些問題。在IE將HTML轉換爲PDF的正確方法
- 打印HTML頁面通過
PDFCreator
(太麻煩) - 使用
wkhtmltopdf
(低質量) - 使用
PhantomJS
(低質量)
也許我可以用一個複雜的解決方案?要使用PhantomJS
到PDFCreator
進行打印,還是要提高wkhtmltopdf
的質量,或者其他方法?
我想將HTML頁面轉換爲PDF。有幾種選擇,但他們有一些問題。在IE將HTML轉換爲PDF的正確方法
PDFCreator
(太麻煩)wkhtmltopdf
(低質量)PhantomJS
(低質量)也許我可以用一個複雜的解決方案?要使用PhantomJS
到PDFCreator
進行打印,還是要提高wkhtmltopdf
的質量,或者其他方法?
也許你可以試試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);
}
平時免責聲明適用。
你能告訴你正在使用的wkhtmltopdf的版本嗎? – pomaxa
版本0.11.0 rc2 – ChruS
你試過0.9版本(最後一個穩定版本)嗎?因爲我沒有任何質量問題。 – pomaxa