How can I generate a Word Document or a PDF using a razor view (for determining how it is layed out) in ASP.NET MVC 3? Probably through the use of something like OpenXML SDK (for WordprocessingML) or iTextSharp (for PDF). I want to enable those that know HTML to be able to change the look of a generated Word Document or PDF without needing to write any C# code.
I had a similar question, and ended up using http://code.google.com/p/wkhtmltopdf/
It generates PDF from HTML (that you can render using the usual Razor view). The result is very good. You may need to render you view into memory string, see here.
As for doc, you can specify content type to be Microsoft Word while sending HTML inside, Word will accept and convert it. E.g. see here.
If you want users to change the final document, you can render you view and set contenteditable for the resulting HTML. E.g.
<div contenteditable>GENERATED HTML</div>
Or use something like TinyMCE. Then, when users post back this HTML, you use it to pass to wkhtmlpdf and you get PDF.
I just implemented Rotavia into my project. It took about 5 minutes to get working.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With