Razor View To Word Document or PDF

How can I generate a Word or PDF document using a razor view (to determine how it is laid out) in ASP.NET MVC 3? Probably using something like the OpenXML SDK (for WordprocessingML) or iTextSharp (for PDF). I want those who know HTML to be able to change the appearance of the generated Word Document or PDF without having to write C # code.

+4
source share
3 answers

I had a similar question and ended up using http://code.google.com/p/wkhtmltopdf/

It generates PDF from HTML (which can be done using the usual Razor view). The result is very good. You may need to display the view in a memory line, see here .

As for doc, you can specify the type of content as Microsoft Word when sending HTML inside, Word will accept and convert it. For instance. see here .

If you want users to change the final document, you can visualize the viewing and set the content for the resulting HTML. For instance.

<div contenteditable>GENERATED HTML</div> 

Or use something like TinyMCE . Then, when users submit this HTML, you use it to go to wkhtmlpdf and you get the PDF.

+5
source

I just introduced Rotavia to my project. It took about 5 minutes to work.

+4
source

This question is a bit old, but for future visitors, I wrote a blog post on how to return a regular MVC view as a Word document.

http://benjii.me/2014/01/download-an-asp-net-mvc-view-as-a-word-document/

The bulk of this functionality comes from the action filter I created by the WordPocateAttribute: https://gist.github.com/bjcull/8702230

+3
source

All Articles