Winnovative HTML 到 PDF 转换器

发布于 2024-11-10 13:29:00 字数 941 浏览 4 评论 0原文

我正在尝试使用 Winnovative HTML 到 PDF 转换器将 aspx 页面转换为 PDF,但在转换页面之前,我想要运行一些 javascript。我知道 javascript 可以工作,因为我已经测试了独立的 aspx 页面,而没有将其转换为 PDF。然而,当它被转换时,似乎javascript还没有运行。我已阅读 Winnovative 网站 (http://www.winnovative-software.com/FAQ.aspx) 上的常见问题解答,因此我将以下内容添加到我的代码中以确保可以允许 javascript 运行

pdfConverter.ScriptsEnabled = True
pdfConverter.InternetSecurityZone = InternetSecurityZone.LocalMachine

:代码仍然不起作用,所以我尝试注释掉我的主要 javascript 并测试一个非常简单的 javascript 来看看它是否有效。我尝试的 JavaScript 很简单:

var item = $(".items")[0];
items.style.display = "none";

具有“items”类的元素包围页面上的所有内容。当我再次生成PDF时,所有内容都如预期消失了。这意味着 JavaScript 正在运行。

然后我想知道是否可能在我的 JavaScript 有机会运行之前生成了 PDF,所以这就是看不到效果的原因。我在Winnovative网站的常见问题解答中发现PDF转换器有一个ConversionDelay属性,可用于指定在开始PDF渲染之前等待异步内容加载的额外时间段(以秒为单位)。所以我添加了以下内容:

pdfConverter.ConversionDelay = 30

即使经过此延迟,我的 javascript 仍然无法运行。有人可以提供任何指导吗?谢谢。

I'm trying to convert an aspx page to a PDF using the Winnovative HTML to PDF converter, but before the page is converted, I want some javascript to be run. I know the javascript works as I've tested the standalone aspx page without converting it to a PDF. However, when it is converted, it appears that the javascript hasn't been run. I have read the FAQs on the Winnovative website (http://www.winnovative-software.com/FAQ.aspx) and as a result I've added the following to my code to ensure javascript can be allowed to run:

pdfConverter.ScriptsEnabled = True
pdfConverter.InternetSecurityZone = InternetSecurityZone.LocalMachine

Adding this code still didn't work so I tried commenting out my main javascript and testing a very simple bit of javascript to see if that works. The javascript I tried was simply:

var item = $(".items")[0];
items.style.display = "none";

The element with a class of "items" surrounds everything on the page. When I generated the PDF again, all the contents had disappeared as expected. This means that javascript is running.

I then wondered if maybe the PDF is being generated before my javascript has had a chance to run so that's why the effects can't be seen. I found in the Winnovative website's FAQs that the PDF converter has a ConversionDelay property which can be used to specify an additional period of time in seconds to wait for asynchronous content to be loaded before starting PDF rendering. So I added the following:

pdfConverter.ConversionDelay = 30

Even after this delay, my javascript still does not run. Can anyone please offer any guidance? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一场信仰旅途 2024-11-17 13:29:00

我发现 winnovative 的另一个产品“EVO HTML to PDF Converter for .NET”可以很好地执行 javascript,它也可以与 jquery 一起使用。

这是测试页面:http://www.evopdf.com/evopdfdemo/default.aspx 我尝试使用这些 jQuery 呈现的页面成功进行转换:

jQuery Accordion(选项卡已正确呈现)

jQuery 分页(jquery 创建的页码可见)

在这两个示例中,winnovative html 到 pdf 的转换失败。


编辑:EVO 库似乎在相关脚本上存在问题,包括不以“/”开头

如果您需要链接外部脚本,您有三个选项:

  1. 使用绝对路径添加脚本引用,例如

    
    
  2. 使用

  3. 使用带有“/”的相对路径

    
    

I found that another product from winnovative "EVO HTML to PDF Converter for .NET" does a good javascript execution, it works also with jquery.

Here is the test page:http://www.evopdf.com/evopdfdemo/default.aspx and I tried the conversion successfully with these jQuery rendered pages:

jQuery Accordion (the tabs are correctly rendered)

jQuery pagination (the pages numbers created by jquery are visible)

In this two examples the winnovative html to pdf conversion fails.


EDIT: It seems that the EVO library has problem on relative scripts include not starting with "/"

If you need to link an external script you have three options:

  1. Add a script reference using the Absolute Path like

    <script src="www.myserver.com/myjsfile.js" type="text/javascript"></script>
    
  2. Insert the script inside the original page using the <script> tag

  3. Use a relative path with "/" like

    <script src="/myjsfile.js" type="text/javascript"></script>
    
慈悲佛祖 2024-11-17 13:29:00

此问题的一种解决方法是在浏览器上运行 JavaScript 之后保存页面源代码,然后将该 HTML 文件传递​​给转换器。

您可以安装适用于 Firefox 的 Web 开发人员工具栏 并使用“查看源代码 ->”查看生成的源功能可获取页面当前状态的 HTML,然后将其保存到文件中。

One workaround for this problem would be to save the page source after JavaScript has run on a browser, and then pass that HTML file to the converter.

You can install the Web Developer Toolbar for Firefox and use the View Source -> View Generated Source feature to get the HTML of the page in its current state, and then save that to a file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文