Can FullCalendar be printed to PDF?

谁说胖子不能爱 提交于 2019-11-29 10:25:58

问题


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?


回答1:


Your best bet is probably wkhtmltopdf, which uses the WebKit as the rendering engine. This means you can freely use CSS/Javascript. You might need to look into the javascript-delay option.

I have used wkhtmltopdf successfully in Ruby on Rails, but it appears you are using .NET. A quick search reveals some possible wkhtmltopdf wrapper libraries for .NET:

  • gmanny/Pechkin
  • codaxy/wkhtmltopdf

You may want to take a look at this answer for some alternative solutions.




回答2:


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.



来源:https://stackoverflow.com/questions/19546745/can-fullcalendar-be-printed-to-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!