Question

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?

Was it helpful?

Solution 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.

OTHER TIPS

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:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top