gpt4 book ai didi

html - 将 HTML 转换为 PDF 的正确方法

转载 作者:太空宇宙 更新时间:2023-11-04 13:23:31 25 4
gpt4 key购买 nike

我想将 HTML 页面转换为 PDF。有几种选择,但它们有一些问题。

  • 通过PDFCreator在IE中打印HTML页面(太繁琐)
  • 使用wkhtmltopdf(低质量)
  • 使用 PhantomJS(低质量)

也许我可以使用复杂的解决方案?要通过 PDFCreator 使用 PhantomJS 进行打印,或者提高 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);
}

适用通常的免责声明

关于html - 将 HTML 转换为 PDF 的正确方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12837560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com