RL Carter RL Carter - 1 year ago 58
C# Question

Automate conversion of Html Page to MS Word Document, save, then load on client machine

I’ve been assigned a task, one which I’ve never done before, to generate a resume using data from our online job application web site, which a user client can display as a web page and then save to their local system in one of two formats, MS Word or PDF. The resume web page is a fixed layout which contains the clients contact information, education, work history and other relevant stuff. I already have a JavaScript plug-in for generating a PDF file on the client side, I’m now looking for a solution to create the MS word document on the client side and save either one to the client file system. The resume page is a single page with a fixed layout, customized only by data stored in the system for the user.

To see other details on the web applications follow this link: Express Professionals

Here are some of the more important requirements I have to take into consideration:

  • We are a Microsoft shop and use 3rd party solutions which adhere to those standards.

  • Windows Server 2012 R2 and IIS 8.5 - Forms Authentication - SQL Server 2012 backend

  • MVC4 internet application with Razor web pages

  • Bootstrap 3.0, JQuery 1.11, JQuery UI 1.8.24, OData 5.2

  • The application must be responsive from desktop to hand held devices

  • Target client browsers are IE 9.0 and up, Chrome 42.0 and up, Safari for MAC 8.0.6 and up - No commercial or 3rd party paid libraries or paid plug-ins. If I can’t find a free solution; I need to invent my own

  • No popup windows or other web pages to collect user input on where to store the finished document on the client machine

  • A single button click, one for PDF and one for MS Word, will take the Html resume page displayed, convert it, then save it, to the client’s machine in the chosen format, then launch the client app and load the document

  • The user can then decided where they want to save the file

  • If the resume page can’t be converted to the native client application file format, it can be saved to the file system in the next best compatible file format which the client application can read

  • Saving the converted file is OK, but it is preferred to launch the client application and load the converted file on the client machine as part of a complete process

  • SharePoint services or SharePoint Server are not available for use in solving this problem.

As I stated, I have found a JavaScript plug-in for creating the PDF, but for the MS Word document, I have only found bits and pieces which are unrelated, nothing in part or as a whole, which can be cobbled together into a working solution using our development stack.

Any references or links that match the requirements or suggestions which get me closer to an end solution are welcomed.

Thanks in advance….

Answer Source

After evaluating several open source solutions, the final choice was OpenXML for MS Word conversions. An MS Word template was created with the basic framework and then the OpenXML utility was used to create the class that builds the word doc. That class was customized to allow a data source to be added to the constructors and data added to tables in the document. DevExpress was used for the PDF conversions, since I don't know this tool the last part was handed off to another developer.