Downloading a PDF from a HTML string out of a View in ASP.NET MVC
<p>I am trying to get download a PDF parsed from a form's HTML code using NReco.PdfConverter. After finding out AJAX isn't going to work I went with form actions per suggestion in numerous posts. However, this raises new issues I can't figure out on my own:</p>

<ol>
<li>How can I use a model to replace the ugly <code>[ValidateResponse(false)]</code> in my controller?</li>
<li><strike>How can I make sure the file actually gets opened?</strike></li>
<li><strike>Formatting the HTML string in the right way so that PdfGenerator can work with it.</strike></li>
<li>Adding CSS to the PDF</li>
</ol>

<p>EDIT:
Ok I updated the Controller code, I can now succesfully create a PDF file. I added the following lines of code:</p>

<pre><code>Response.ContentType = "application/pdf";
Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.AddHeader("Content-Disposition", "inline; filename=test.pdf");
Response.BinaryWrite(pdfBytes);
</code></pre>

<p>However the contents are not what I expect. I suspect the JSON.stringify isn't correctly formatting the string. Turns out i was using the wrong jQuery selector and actually selected the form that contained the print button. That being fixed I can now succesfully load the HTML string into the PDF, except it's missing the CSS. How can I make sure that the PDF looks exactly like the webpage using te PdfConverter?</p>

<p>Html:</p>

<pre><code>&lt;form action="User/Template/Print" method="POST" id="print-form" enctype="multipart/form-data"&gt;
    &lt;input type="text" hidden ng-model="strHtml" name="strHtml" ng-init="printToPdf()" /&gt;
    &lt;button class="btn btn-success" type="submit"&gt;@Html.Raw(new Icon("print").Html) Print&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>AngularJS:</p>

<pre><code>angular.module("app").controller("FormController", function ($scope) {
    $scope.printToPdf = function () {
        var strHtml = $('#werkorderFormulier form').html();
        $scope.strHtml = JSON.stringify(strHtml);
    }
});
</code></pre>

<p>Print action in TemplateController:</p>

<pre><code>public FileResult Print(FormCollection fC)
{
    var pdfConverter = new HtmlToPdfConverter();
    var strHtml = fC.GetValue("strHtml").AttemptedValue;
    var pdfBytes = pdfConverter.GeneratePdf(strHtml);
    Response.ContentType = "application/pdf";
    Response.ContentEncoding = System.Text.Encoding.UTF8;
    Response.AddHeader("Content-Disposition", "inline; filename=test.pdf");
    Response.BinaryWrite(pdfBytes);
    return File(pdfBytes, "application/pdf");
}
</code></pre>