gpt4 book ai didi

javascript - 在 wkhtmltopdf 进程中运行脚本

转载 作者:行者123 更新时间:2023-11-28 07:37:40 27 4
gpt4 key购买 nike

我使用 wkhtmltopdf 从 html 创建 pdf

我有下一个功能:

private void CreateTempPdf(string htmlPath, string pdfPathTemp)
{
var processorInfo = new System.Diagnostics.ProcessStartInfo
{
Arguments =
"--margin-top 27 \"" + htmlPath + "\" \"" + pdfPathTemp +
"\" ",
FileName = PublisherConfigurationManager.Pdf2HtmlConverter,
UseShellExecute = true
};

using (var proc = new System.Diagnostics.Process())
{
proc.StartInfo = processorInfo;
proc.Start();
proc.WaitForExit();
}
}

其中我传递html文件和目标文件的路径。

我想在生成 pdf 之前添加一些要运行的 js 脚本。

我添加我的代码:--run-script <js>进入Arguments之后pdfPathTemp但脚本不适用于 pdf。我也在--margin之前添加了它但这个案例也对我没有帮助。

如何正确地将脚本添加到wkhtmltopdf进程中?

最佳答案

我只需将脚本直接添加到 HTML 页面中即可。在本例中,我会将路径中的 HTML 加载到字符串中,注入(inject)脚本,然后在进程持续时间内编写一个临时文件。

至于为什么 --run-script 不起作用,我不知道。您是否使用非常简单的脚本和 HTML 直接在命令行中尝试过,看看最小的示例是否适合您?

如果这不是一个选项,如果您需要这样的东西,您可能必须使用不同的文件来处理不同的 js 参数。

关于javascript - 在 wkhtmltopdf 进程中运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28413291/

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