After spending hours and hours on StackOverflow and programmers forum, i've decided to use the SyncFusion on our project.
Our main target is :
convert to PDF/directly print existing Doc And Docx
this Document can be quite complexe (including shapes, images....)
using Word Interop can not be a solution for us
If we are able to convert or print without problems, the orginal Word documents are not well rendered (parts of shapes missing...)
Somebody is using this component without problem ? Or do you knows others best components (Aspose ??)
Yes, you can meet these requirements using Aspose.Words. With Aspose.Words for .NET API, you can easily render any complex Microsoft Word document or Text/Html/Mhtml file to PDF format with high fidelity. Please see the following simple code:
// Load Word document in memory for processing
Document doc = new Document(MyDir + "Document.docx");
// Send it directly to printer
doc.Print("printerName");
// Convert DOCX to PDF
doc.Save(MyDir + "DocxToPdf.pdf");
This means that if you convert a Microsoft Word document into PDF, XPS or print it using Aspose.Words, the output will appear almost exactly as if it was done by Microsoft Word application. Please check Aspose.Words for .NET Documentation for more details.
I work with Aspose as Developer Evangelist.
Can you please send your example document to Syncfusion by creating a support ticket and we will able to check and provide a solution. (I work for Syncfusion)
Ty for all the answers (in this post and other on SO).
But after trying :
4 or 5 .Net Libraries
Using very simple, but also complex Doc and Docx Files
And specialy with complex doc file, mixing complex shapes, grouping schemes, img import....
Here is my conclusion (imo) :
there is no better processing (printing and creating PDF) than using Ms Office and it's automation from .Net
and even if it is not recommended by MS itseflf, we are very sastified of our "doc printing server"
it is printing more than 30 or 50 "Build of Manufacturer" with more than 30 pages each, and also with A3 plan.
it is working very well for 4 month, without major bug
If somebody is interested, i can post the tips and link i have used to properly use MS Office in a "Windows Printer Server mode".
Best regards from Toulouse
Docentric Toolkit is primarily a mail merge library but also has a complete DOM and a high fidelity PDF/XPS rendering engine. Still I haven’t try to convert a Word document containing decorations and styles with effects.
document = Document.Load("Test1.docx");
document.Save("Test1.pdf");
Related
I need to convert .doc and .docx document format to pdf in the server side using .net core. I've searched for it, and it came to this question that has remarkable answered for .docx to pdf issue. It said that you have to convert it first to HTML format using OpenXMLPowerTools, and from HTML to pdf. And you may see in the answer, that there's a solution for the conversion from .doc to .docx, and that using b2xtranslator, a library to convert Microsoft Office binary files to Open XML format files. What I am missing here is the usage of this library. I can't find any sample how to use it to convert the .doc file, but only this comment on this question.
Based on that, I tried to use the library, but I met a dead end. This is my code:
//check file extension
FileInfo file = new FileInfo(textBox1.Text);
if (file.Extension == ".doc")
{
FileStream streamDocFile = new FileStream(file.FullName, FileMode.Open);
var fileDoc = new b2xtranslator.DocFileFormat.WordDocument(new b2xtranslator.StructuredStorage.Reader.StructuredStorageReader(streamDocFile));
var fileDocx = b2xtranslator.OpenXmlLib.WordprocessingML.WordprocessingDocument.Create(file.Name + "x", b2xtranslator.OpenXmlLib.OpenXmlPackage.DocumentType.Document);
b2xtranslator.WordprocessingMLMapping.Converter.Convert(fileDoc, fileDocx);
}
My questions are:
How to write the .docx file? I don't know if the code is right or not, because I am confused about how to write it (fileDocx object) to file and to check it.
How to pass .docx resulting in b2xtranslator, to Open-XML-PowerTools, so I can convert it into HTML format?
Thank you in advance.
Finally, the decision was using 3rd party library for document processing. Because we need library that stable for document processing, and we have short time to finish the project, our company decided to buy 3rd party library.
This answer is not very helpful for those who looking for a free way to process the doc. May you have found a better one.
Thank you
TL;DR see the OP answer that this route was simply too problematic, and paid is usually cheaper (lower Total Cost of Ownership, Faster To Market, and someone else to provide support with the tricky bits.).
Practically all means to convert MS Word processor formats (RTF WPS DOC DOCx) to PDF should be direct such as Adobe Word Plug-in or MS export/save as PDF etc.
If you need to use B2X.net interop(erability) see code using Microsoft.Office.Interop.Word; there are still legacy dependencies to be considered. https://learn.microsoft.com/en-us/archive/blogs/interoperability/binary-to-open-xml-b2x-translator-interoperability-for-the-office-binary-file-formats potentially an older full suite of .net and older MS Office, (my attempts to install older.net failed on win 11).
The second best alternative is use Current Open Office, which should direct convert Doc to PDF exports. Here is the B2X demo.doc showing as default open in LO Writer 7.4 and default export as PDF.
Libre-Office has good command line conversion and "Basic App"/DDE support so you can control any adjustments needed. For current command line in out filters and thus the different types of MS.doc version support see https://help.libreoffice.org/7.4/en-US/text/shared/guide/convertfilters.html?&DbPAR=SHARED&System=WIN
Microsoft WinWord 1/2/5 "MS WinWord 5"
application/msword (doc)
Microsoft Word 6.0 "MS WinWord 6.0"
application/msword (doc)
Microsoft Word 95 "MS Word 95"
application/msword (doc)
Microsoft Word 95 Template "MS Word 95 Vorlage"
application/msword (dot)
Word 97–2003 "MS Word 97"
application/msword (doc wps)
Word 97–2003 Template "MS Word 97 Vorlage"
application/msword (dot wpt)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
We have a database application that stores data that we want to report in Microsoft Word.
Suppose all information of my customers is stored on a database system and I am now requested to create hundreds of word letters, reports that will be sent to my customers. These letters have the same content but different customer name, customer address, etc.
I want to make use of Office Word 2010 by creating document template with content controls using c# and .Net, sql as database to replace the content of this template.
I've been looking for articles on automating Word 2010 in C# and dot net and sql. Could someone give me a push in the right direction?
You can use Interop.Word in your program, but keep in mind that the available documentation is very scarce. I managed to develop my application looking at examples like this one from C-SharpCorner or this one from WindowsDevCenter. Even if the examples are old, you can get the main idea and get familiar with the syntax, and write your program afterwards with an updated version of Interop.Word (which has a slightly simpler syntax).
In your case, you should create a neat Word template, with bookmarks located in the places of your document where you will insert the customer information. Then you can open the template from your program and navigate it using those bookmarks, as you insert the information retrieved from your database.
There are other interesting alternatives to Interop.Word that you could try if you don't want to go too deep into Word automation, such as DocX (which doesn't even require Microsoft Word or Office to be installed) or Open XML (to generate .docx files).
I've used the Office.Interop assemblies in the past for this kind of functionality but this method carries a few distinct disadvantages:
Word must be installed on the machine where the code is running
The Interop assemblies actually start up Word in the background, so you have to be careful to dispose of everything properly and handle errors, otherwise you'll end up with Word processes wasting CPU/Memory on the host server
The APIs are not very pleasant to work with and documentation is somewhat scarce
I've also played with DocX and Open XML, both of which have their merits but tend to be slightly limited by comparison with Interop. My advice would be to attempt the functionality using DocX or Open XML and only fall back to Interop if you can't achieve the functionality any other way. There should be plenty of tutorials online for all three APIs.
Microsoft recommends OpenXml for any application running in a server process, and this approach would probably be one of the best for reducing dependencies (as others have mentioned). Here are some links to get you started:
Download OpenXml SDK 2.0: http://www.microsoft.com/en-au/download/details.aspx?id=5124
Useful Tutorials: http://msdn.microsoft.com/en-us/library/ff478255.aspx
So for start DO NOT USE INTEROP, i've been using it for the last 4 years, and i have to tell u it's not a good idea (it's really lost, and u'll hit lots of problems. It's actually written on Microsoft's site that you shouldn't use it for server side generation.
You should use the OpenXML SDK, i've actually just started using it but i have to say that even if it seems a bit harder to use, it's definetly a lot faster that using interop and the best thing is that know i don't need any programs from the Office suite to be installed on my pc, the downside is that i can't export to PDF or XPS anymore without a 3rd party library
You can find the sdk here
http://www.microsoft.com/en-us/download/details.aspx?id=30425
I suggest downloading the tool as well it's pretty useful.
This is a good tutorial to start with it really helped me a lot.
http://msdn.microsoft.com/en-us/library/office/bb448854.aspx
And u can also use the API documentation from the Productivity Tool which is on the same site as the sdk
I agree with others that the OpenXML SDK is a good way to go for the same reasons. I am in the midst of creating a similar kind of report generation as you are. The reports I need to generate unfortunately are very dynamic not only with data but with the layout.
If your layout does not need to change then I would strongly suggest using the SDK Tool, it lets you take any word document and generate the c# code for you to recreate the same exact doc. From that point all you have to do is replace the text with the data you want in the code.
You could make a generic report in word, get the code with the tool, then just do a search for the placeholder text in the code and replace that string with a variable. its as easy as text1.text = reportData;
I also find the SDK Tool a great way to learn the code, you can compare two files side by side and see how they differ in the code.
Your answer is OpenXML SDK.
goto Open XML SDK 2.5 for Microsoft Office
download OpenXMLSDKV25 and OpenXMLSDKToolV25
install sdk and productivity tool
open word and create your template document
open Open XML SDK Productivity Tool
open word document
right click on document name from Document Explorer and select reflect code
copy all generated code to your project
find and edit "Paragraph" or "Run" that you want replace with your data
I have used both interop and syncfusion to create reports (although I was generating an excel report but both technologies can be used to generate word reports also). My feedback :-
Although interop is included in most computers which have visual studio (not sure about non visual studio computers), usage of interop requires the presence of compatible microsoft excel also on the computer generating the report whereas syncfusion does not requires the presence of microsoft excel on the same computer.
If you plan to use asp.net, then interop is not supported (atleast it was not when I worked) whereas syncfusion is supported.
Link for syncfusion :-
http://www.syncfusion.com/products/aspnet/docio
Summary :- If you are developing a console application and server(where the application will be deployed) has microsoft office installed, then interop might be a good idea. Otherwise, you can have a look at syncfusion also.
You can usee Free .NET Word API to generate report in word 97 ~ 2010 using c#.
//Create word document
Document document = new Document();
document.LoadFromFile(#"..\..\..\..\..\..\Data\Fax.doc");
string[] filedNames = new string[]{"Contact Name","Fax","Date"};
string[] filedValues = new string[]{"John Smith","+1 (69) 123456",System.DateTime.Now.Date.ToString()};
document.MailMerge.Execute(filedNames, filedValues);
//Save doc file.
document.SaveToFile("Sample.doc", FileFormat.Doc);
Given a list of mailing addresses, I need to open an existing Word document, which is formatted for printing labels, and then insert each address into a different cell of the table. The current solution opens the Word application and moves the cursor to insert the text. However, after reading about the security issues and problems associated with opening the newer versions of Word from a web application, I have decided that I need to use another method.
I have looked into using Office Open XML, but I have not found any good resources that provide concrete information on exactly how to use it. Also, someone suggested that I use SQL reporting services, but searching for information on how to use them, lead me nowhere.
Which method do you think is the most appropriate for my problem?
Code samples and links to good tutorials would be extremely helpful.
Thanks for all the answers, but I really did not want to pay for a plugin and using Word automation was out of the question. So I kept searching and eventually, through some trial and error, found some answers.
After throughly searching through Microsoft's site, I found some newer articles on the Office Open XML SDK. I downloaded the new tools and just started going through each them.
I then found the Document Reflector, which creates a class to generate XML code based off an existing Word Document (.docx). Using my Label Template Document and the code this tool generated, I went through and added a loop that appends table cells for each address. It actually proved to be fairly simple and way faster than using Word automation.
So, if you're still using Word automation check out the Office Open XML tools. Their surprisingly extensive for a free download from Microsoft.
Office Open XML SDK 2.0 Download
I use the Words plugin from Aspose.com to do mail merges (programming guide).
You can take a look show 137 and 138 on dnrTV (www.dnrtv.com). In these video's Beth Massi shows how to do some editing and mail merging with OpenXML. She does this by using the Open XML SDK and xml literals in VB. It requires no third party components. Also it doesn't require MS Office to be installed on the machine.
This video inspired me as a C# developed (and no VB experience) to do some XML manipulation in a separate dll in VB. I call into this dll from my C# application.
It is worth a try.
We have the product Aspose that tvanfosson has mentioned. The edition that we purchased works with SQL Reporting Services so it can be used with the scheduler for creating output. It is really a great product and we used in a system that needed to support Korean characters in the final document. It works great and was under $1K with support. Not bad.
The advantage of using a product like this is that you can continue to manage your data and the skill set required to produce the documents is at a level where a variety of developers can support its use.
Vanstee,
If you really want to do this in code, check out this post I just found on Google
http://kellychronicles.spaces.live.com/blog/cns!A0D71E1614E8DBF8!1364.entry
If you are using reporting services cant you just move the information in the word doc into a database table and read it from there, taking word out of the equation?
I'd like to dynamically generate content and then render to a PDF file. This processing would take place on a remote hosting server so using virtual printers etc is out. Does any have a recommendation for a .NET library (pref C#) that would work?
I know that I could generate a bunch of PS code and package it myself but I'd prefer something a little less tricksy at this stage.
Thanks!
Have a look at http://itextsharp.sourceforge.net/. Its open source.
Tutorial: http://itextdocs.lowagie.com/tutorial/
I have had good success using SharpPDF.
I have had success using Siberix
http://www.siberix.com/
Corporate License: $350 USD (A single license covers unlimited number of company's developer seats, unlimited number of company's web servers and unlimited number of distributions as a part of your application.)
Free PDF Generator .NET (WkHtmlToPdf wrapper) can generate pretty PDF from HTML template with one line of code:
var pdfBytes = (new NReco.PdfGenerator.HtmlToPdfConverter()).GeneratePdf(htmlContent);
(all you need is one DLL, no external dependencies)
We use the Amyuni PDF Converter and have used it successfully for several years. Our usage is via the COM interface, but it does support a .NET interface.
I've had good experiences with Winnovative's HTML to PDF.
And bad ones with Open Source HTML Doc (Problems with form elements + CSS).
I have been looking for a high performing docx to pdf tool for a while now. Our system has an e-government aspect and is generating a very high number of reports to the user community. At this point, performance is paramount.
Earlier tools I have used did not do simultaneous conversion, instead each exe needed to wait for completion of the other. I have tried Aspose.words and I am very happy with the results.
First of all, it was very easy and seamless to integrate and deploy in our project. Very smooth.
Secondly, the speed of conversion is way better due to the fact that multiple jobs run in parallel.
Thirdly, not only fast, but even with no formatting errors. Considering that we are providing a multi-lingual system and some reports include both English and Arabic fields (mind right-to-left alignment!), this was very important.
And finally, the file size was quite small, which again is very important as tens of thousands of documents are created through our system.
Our first implementation was Microsoft Office Interop library. We convert docx to pdf documents by using below code. This library converts the docx documents to pdf files perfectly and we decided to upload this to report generation server. But after a while, we noticed that conversion operations are waiting for each executable. This causes a big delay on converting the documents at the same time and that's why we start to search a new tool for converting docx files to pdf files.
See Image
Below code shows the how to convert docx documents to pdf files by using Aspose.Words for .NET tool.
See Image 2
RDLC & the Report Viewer controls can generate PDF either at the Client's discretion or at server command which can then be served as a PDF mime-type.
I've used PDF4NET from O2solutions with much success. They support all sorts of scenarios and digital signing of the pdf.
If your data is mostly in XML, you could also look at a XSL-FO solution - we're using Alt-Soft's Xml2Pdf with great success. The "server" version is a bit of a misnomer - it's really just a single DLL you need to include in your Winforms, WPF or ASP.NET app - that's all!
Works like a charm (if you're familiar with XSLT and XSL-FO, or willing to learn it).
Marc
We used a set of third party DLLs from PDFSharp who in turn use DLLs from MigraDoc. I'm not privy to all the reasons that we went that direction (the decision was made by a senior developer), but I can tell you that:
It seems to be in active
development.
It had most of the
features we needed.
The source code
is available. Although it used some
patterns and conventions that I
hadn't seen before, once I got on to
them, it was fairly easy to make the
changes. I added support for using
the System.Drawing.Image directly
rather than as saving files.
It is
not documented well either
internally or externally.
I used iTextSharp in .NET 6 as shown below, but it had an issue of loading scripts and cdn(s) for loading stylesheet, it only works with inline styles. these bytes can be saved using File.WriteAllBytes()
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Net.Http;
using PageSize = iTextSharp.text.PageSize;
public static byte[] GenratePdfBytes(string htmlContent)
{
byte[] pdfBytes;
var pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
var html = new StringReader(htmlContent);
var htmlparser = new HTMLWorker(pdfDoc);
using (var memoryStream = new MemoryStream())
{
var writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
pdfDoc.Open();
htmlparser.Parse(html);
pdfDoc.Close();
pdfBytes = memoryStream.ToArray();
}
return pdfBytes;
}
There are a few ways to do this, in my experience, and it depends on the application and complexity of what you are trying to generate and whether the resulting PDF needs to be a commercial print-ready file or just a PDF report for sharing/archiving etc, and what sort out volume output, based on budget. Most higher end PDF libraries come with a large price tag.
I have used various techniques based no the complexity, there are libraries to generate PDF (build PDF elements from the ground up) in this case you could use something like iText or others that can add content on top of a PDF.
If you need to do minor adjustments i.e. use an existing PDF as a template and add some content (text/images) there are libraries that can just stamp text and images on top. (eg: http://www.pdfsharp.net/)
If you generating invoices or reports, you could use an HTML template, merge data (replacing {tokens} etc) and then convert the html to pdf using a different type of mechanism (eg: https://www.nrecosite.com/pdf_generator_net.aspx)
There are API's if you need full control over styling, client generated templates (idml) etc, you can integrate with InDesign Server and use that to generate print ready PDF files. I have build an API like this but this is another level of PDF generation.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a project where I would like to generate a report export in MS Word format. The report will include images/graphs, tables, and text. What is the best way to do this? Third party tools? What are your experiences?
The answer is going to depend slightly upon if the application is running on a server or if it is running on the client machine. If you are running on a server then you are going to want to use one of the XML based office generation formats as there are know issues when using Office Automation on a server.
However, if you are working on the client machine then you have a choice of either using Office Automation or using the Office Open XML format (see links below), which is supported by Microsoft Office 2000 and up either natively or through service packs. One draw back to this though is that you might not be able to embed some kinds of graphs or images that you wish to show.
The best way to go about things will all depend sightly upon how much time you have to invest in development. If you go the route of Office Automation there are quite a few good tutorials out there that can be found via Google and is fairly simple to learn. However, the Open Office XML format is fairly new so you might find the learning curve to be a bit higher.
Office Open XML Iinformation
Office Open XML - http://en.wikipedia.org/wiki/Office_Open_XML
OpenXML Developer - http://openxmldeveloper.org/default.aspx
Introducing the Office (2007) Open XML File Formats - http://msdn.microsoft.com/en-us/library/aa338205.aspx
DocX free library for creating DocX documents, actively developed and very easy and intuitive to use. Since CodePlex is dying, project has moved to github.
I have spent the last week or so getting up to speed on Office Open XML. We have a database application that stores survey data that we want to report in Microsoft Word. You can actually create Word 2007 (docx) files from scratch in C#. The Open XML SDK version 2 includes a cool application called the Document Reflector that will actually provide the C# code to fully recreate a Word document. You can use parts or all of the code, and substitute the bits you want to change on the fly. The help file included with the SDK has some good code samples as well.
There is no need for the Office Interop or any other Office software on the server - the new formats are 100% XML.
Have you considered using .RTF as an alternative?
It supports embedding images and tables as well as text, opens by default using Microsoft Word and whilst it's featureset is more limited (count out any advanced formatting) for something that looks and feels and opens like a Word document it's not far off.
Your end users probably won't notice.
I have found Aspose Words to be the best as not everybody can open Office Open XML/*.docx format files and the Word interop and Word automation can be buggy. Aspose Words supports most document file types from Word 97 upwards.
It is a pay-for component but has great support. The other alternative as already suggested is RTF.
To generate Word documents with Office Automation within .NET, specifically in C# or VB.NET:
Add the Microsoft.Office.Interop.Word assembly reference to your project. The path is \Visual Studio Tools for Office\PIA\Office11\Microsoft.Office.Interop.Word.dll.
Follow the Microsoft code example
you can find here: http://support.microsoft.com/kb/316384/en-us.
Schmidty, if you want to generate Word documents on a web server you will need a licence for each client (not just the web server). See this section in the first link Rob posted:
"Besides the technical problems, you must also consider licensing issues. Current licensing guidelines prevent Office applications from being used on a server to service client requests, unless those clients themselves have licensed copies of Office. Using server-side Automation to provide Office functionality to unlicensed workstations is not covered by the End User License Agreement (EULA)."
If you meet the licensing requirements, I think you will need to use COM Interop - to be specific, the Office XP Primary Interop Assemblies.
Check out VSTO (Visual Studio Tools for Office). It is fairly simple to create a Word template, inject an xml data island into it, then send it to the client. When the user opens the doc in Word, Word reads the xml and transforms it into WordML and renders it. You will want to look at the ServerDocument class of the VSTO library. No extra licensing is required from my experience.
I have had good success using the Syncfusion Backoffice DocIO which supports doc and docx formats.
In prior releases it did not support everything in word, but accoriding to your list we tested it with tables and text as a mail merge approach and it worked fine.
Not sure about the import of images though. On their blurb page http://www.syncfusion.com/products/DocIO/Backoffice/features/default.aspx it says
Blockquote
Essential DocIO has support for inserting both Scalar and Vector images into the document, in almost all formats. Bitmap, gif, png and tiff are some of the common image types supported.
So its worth considering.
As others have mentioned you can build up a RTF document, there are some good RTF libraries around for .net like http://www.codeproject.com/KB/string/nrtftree.aspx
I faced this problem and created a small library for this. It was used in several projects and then I decided to publish it. It is free and very very simple but I'm sure it will help with you with the task. Invoke the Office Open XML Library, http://invoke.co.nz/products/docx.aspx.
I've written a blog post series on Open XML WordprocessingML document generation. My approach is that you create a template document that contains content controls, and in each content control you write an XPath expression that defines how to retrieve the content from an XML document that contains the data that drives the document generation process. The code is free, and is licensed under the the Microsoft Reciprocal License (Ms-RL). In that same blog post series, I also explore an approach where you write C# code in content controls. The document generation process then processes the template document and generates a C# program that generates the desired documents. One advantage of this approach is that you can use any data source as the source of data for the document generation process. That code is also licenced under the Microsoft Reciprocal License.
I currently do this exact thing.
If the document isn't very big, doesn't contain images and such, then I store it as an RTF with #MergeFields# in it and simply replace them with content, sending the result down to the user as an RTF.
For larger documents, including images and dynamically inserted images, I save the initial Word document as a Single Webpage *.mht file containing the #MergeFields# again. I then do the same as above. Using this, I can easily render a DataTable with some basic Html table tags and replace one of the #MergeFields# with a whole table.
Images can be stored on your server and the url embedded into the document too.
Interestingly, the new Office 2007 file formats are actually zip files - if you rename the extension to .zip you can open them up and see their contents. This means you should be able to switch content such as images in and out using a simple C# zip library.
#Dale Ragan: That will work for the Office 2003 XML format, but that's not portable (as, say, .doc or .docx files would be).
To read/write those, you'll need to use the Word Object Library ActiveX control:
http://www.codeproject.com/KB/aspnet/wordapplication.aspx
#Danny Smurf: Actually this article describes what will become the Office Open XML format which Rob answered with. I will pay more attention to the links I post for now on to make sure there not obsolete. I actually did a search on WordML, which is what it was called at the time.
I believe that the Office Open XML format is the best way to go.
LibreOffice also supports headless interaction via API. Unfortunately there's currently not much information about this feature yet.. :(
You could also use Word document generator. It can be used for client-side or server-side deployment. From the project description:
WordDocumentGenerator is an utility to generate Word documents from
templates using Visual Studio 2010 and Open XML 2.0 SDK.
WordDocumentGenerator helps generate Word documents both
non-refresh-able as well as refresh-able based on predefined templates
using minimum code changes. Content controls are used as placeholders
for document generation. It supports Word 2007 and Word 2010.
Grab it: http://worddocgenerator.codeplex.com/
Download SDK: http://www.microsoft.com/en-us/download/details.aspx?id=5124
Another alternative is Windward Docgen (disclaimer - I'm the founder). With Windward you design the template in Word, including images, tables, graphs, gauges, and anything else you want. You can set tags where data from an XML or SQL datasource is inserted (including functionality like forEach loops, import, etc). And then generate the report to DOCX, PDF, HTML, etc.