FullCalendar可以打印成PDF格式吗? [英] Can FullCalendar be printed to PDF?

查看:285
本文介绍了FullCalendar可以打印成PDF格式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试将FullCalendar.js呈现的日历打印为PDF,但是没有任何可用的生成器可以工作:


  • Aspose PDF确实不允许使用JavaScript,而且直接不支持绝对定位的元素

  • PrinceXML已知问题,它抛出 TypeError exceptions 在处理不能在IE,Chrome或Firefox中重复使用的JavaScript时。


我最小的repro例子是Prince Shaw的FullCalendar网站上的例子。即使我保存生成的HTML(通过 $(body)。html())并将生成的HTML传递给PrinceXML,从而绕过了PrinceXML不正确的JavaScript处理,PrinceXML不会没有正确地摆放绝对定位的事件。

我的选择是什么?

解决方案

我的同事找到了一个更简单的解决方案。在测试环境中,我们遇到了使用Pechkin和wkhtmltopdf的问题。此外,它还要求我们设置一个额外的应用程序池来处理PDF打印。 使用 html2canvas.js

将画布转换为base64。我推荐Fred Palmer的 base64.js



< h1>将base64编码值发送到服务器

创建调用PDF转换器库的Web服务。我们使用Aspose,因此我们所做的只是将图像添加到Aspose PDF对象。



利润!



此解决方案令人难以置信的光滑,因为它使用用户自己的渲染引擎来生成PDF。这意味着所见即所得(What You See Is What You Get),所以如果日历看起来不错,当用户使用它时,它应该以完全相同的方式打印! MONEY。

I have tried printing FullCalendar.js rendered calendars to PDF, however none of the generators available seem to work:

  • Aspose PDF does not allow JavaScript, and straight up just doesn't support absolutely positioned elements
  • PrinceXML has known issues where it throws TypeError exceptions when processing JavaScript that are not reproducible in IE, Chrome or Firefox.

My minimal repro example for PrinceXML failure is the examples on Adam Shaw's FullCalendar site. Even when I save the generated HTML (via $("body").html()) and pass the generated HTML to PrinceXML, thus bypassing PrinceXML's incorrect JavaScript handling, PrinceXML doesn't lay out the absolutely positioned events correctly.

What are my options?

解决方案

My coworker found a simpler solution.

As it turns out, we ran into issues using Pechkin and wkhtmltopdf in test environments. Plus, it required us to set up an additional App Pool just to handle printing to PDF.

Use html2canvas.js library

Convert the canvas to base64. I recommend Fred Palmer's base64.js

Send base64 encoded value to server

Create web service that calls your PDF converter library. We use Aspose, and so all we do is add the image to an Aspose PDF object.

PROFIT!

This solution is incredibly slick, since it uses the user's own rendering engine to generate the PDF. This means WYSIWYG (What You See Is What You Get), so if the calendar looks good when the user uses it, it should print the same exact way! MONEY.

这篇关于FullCalendar可以打印成PDF格式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆