Ok, since I did find out that I can use iTextSharp to generate a PDF, I went that route.
I've got it to where it will save HTML with basic formatting to a PDF. That's not the problem.
What I'm needing to do now is take markup with knockout in it, and use the resultant HTML (i.e. the DOM) as my string to pass into the method that creates the PDF.
So, for instance, I have a table that's generated with knockout. I need to pass the DOM that was generated by knockout, as a string, into my C# controller, so that I can build the PDF.
Basically, if you look at what's generated here:
http://knockoutjs.com/documentation/foreach-binding.html
And if you read through Example 2 (it generates three bullet points), it illustrates the generation I'm talking about. In my case, I would want to take the generated bullet points and pass them into my controller -- HTML and all -- as a string, so that I can save them.
Any thoughts? I'm not even sure where to begin here, honestly.
The question applies to any JavaScript Framework that does
MVC
orMVVM
. Mentioned above:So am going to go with a simple working example to get this done in ASP.NET MVC. Never used
knockout.js
before, so going to get theDOM
element and sendAjax
request withjQuery
.The view, based on the example you referenced above: 1. Gets
outerHTML
oful
; 2. sends anAjax
request to the controller:Notes:
jQuery
- sadly the framework doesn't support this feature out of the box last I checked. Other frameworks likeAngularJS
do support binary. Reference Sending and Receiving Binary Data.jquery-binary.js
is a simplejQuery
Plugin I wrote for a couple of internal projects:And the controller: 1. parses the
HTML
string withXMLWorkerHelper
; 2. returns the PDF.Will let you decide how to deal with the inline styles. ;)