Display a Ms Word 2003 .doc in Silverlight 3 - c#

I'm currently programming an application in Silverlight which need to have a control to display a Word 2003 document . I can also convert the document before the webservice sends it but the 2003 format seems to be quite harsh to manipulate. I know there's some softwares which can do it but you have to purchase them. Do you have any clue to help me to progress ?

What is the level of fidelity you want to achieve?
I am quite sure that the "easiest" way of doing this would be to convert the document to XPS serverside (with the XPS printer perhaps) then manipulating it to create a Silverlight compatible content (a XAP)
Why this? Because, for instance:
Silverlight does not support flow documents, therefore you don't want to have to perform the layout on the client.
Silverlight requires fonts to be included in the same XAP that is using it (even in the same assembly), therefore you need to generate an assembly with the font embedded in it serverside.
XPS is XAML in a zip (therefore a lot better to manage than Word2003 doc), but it isn't Silverlight Xaml, you need to convert it to Silverlight before being able to read it on your Silverlight App (using XSLT? beware, there are some calculations required to convert viewports into scale/translate transforms). The good news is that any layout problems were taken care of in the XPS generation process.
I had an intern design a prototype of XPS reader for Silverlight a year ago. It worked, but the rendering wasn't perfect (I could have been however, with more work)
In a word: It's possible, not really complicated, but requires lot of work and practice in a few domains (from XSLT to assembly generation, and knowledge of the XPS norms). But I am not aware of any free solutions available.
Therefore, I would recommand using an available (and working) solution, rather than taking the route of a risky development.

Related

What options are there for displaying a presentation slideshow in C#?

The Scenario:
I need to create a lightweight presentation application that offers PowerPoint-like features such as:
Simple text formatting (font, colour, size, style, etc)
Picture embedding (possibly video as well)
Simple animations (just slide, fade and appear actually)
The presentations themselves will be arrays (or Dictionaries) of strings from either a built-in database or a series of XML files (probably a combination of both).
I intend to develop and test the application, and create presentations on a Windows PC, and then display (and possibly edit) those presentations on a Linux-based PC.
The Options:
The options I know about are:
WinForms
Pros:
No external code needed
Cons:
Limited screen redrawing ability
Limited/No animations available
HTMLRenderer
Pros:
Proven reliable layout format (HTML 4.01 + CSS Level 2)
Code freely available for embedding
Cons:
Code hasn't been updated since 2009
Author's website gives 404, and his company website is incomplete.
My question is, quite simply, what other options are there? And which would be the best for my needs?
I would be very tempted to do this using Gtk-Sharp and to use WebKitSharp for rendering full HTML documents ( no need to restrict yourself )
You could possibly allow your program to consume a zip file containing html docs and images, perhaps even javascript and css.
Both libraries sould allow you to quite easily write a c# application that will run on mono on linux or OSX or windows with .Net or Mono.
That said, Webkit sharp has not had much in the way of recent checkins..

Easiest way to create dynamic-content documents (like invoices, delivery notes)

I was searching the web with a few results, but none of them seems to fit the task. I was looking für possibilites for .NET, but would also like to know how Java/PHP/etc. developers finish tasks like this.
As far as I found out, I have the option to:
Use MigraDoc/PDFSharp and go the "code" way, without any visual designer
I could use HTML and convert it to a PDF (which is the best approach in theory, but practically it's awful to get good looking HTML 1:1 into a PDF file)
I could use some weird MS Word templateing/batch stuff
LaTeX?
What are your solutions?
We use SoftArtisans OfficeWriter
A solution that we settled on in a previous project was XSL-FO. Although it did not have a visual designer, we found it to be very developer friendly and more suitable to run in a server type environment. It also deals with document "flow" a lot better than most of the reporting software that offer a designer. I do know that we had a lot of trouble with Crystal Reports around deployment, COM exceptions being thrown and limitations on how many reports can be generated concurrently. One downside to using XSL-FO is all the syntactic sugar that comes with XML.
This question lists a few XSL-FO engines.
Regarding your "3.) weird MS Word templateing/batch stuff":
I love to use Aspose.Words, a commercial package to create/edit/export Microsoft Office Word documents, without any Office components being installed.
Aspose.Words is capable of doing Mail Merge stuff and write PDF files, so I often start on my desktop computer with a DOC that I edit in Word and use this with Aspose.Words on my server to produce PDFs.
One method I've used before for Windows desktop applications is to use XAML/WPF. The nice thing about this solution is that there are a lot of good tools and documentation around building layouts with XAML. Then you just pass the canvas to a PrintDialog and you're done. If you've been doing a lot with WPF/XAML already this is a very easy solution and I've had a lot of success with it. I learned most of what I needed to get started here: http://www.switchonthecode.com/tutorials/printing-in-wpf
The downside, of course, is your dependency then on .NET and WPF.
Similar to Matt Fs solution of using Crystal Reports, I use SQL Server Reporting Services. You can create add a rdlc file to your solution and use the WYSIWYG editor to design your report. Then in your code, all you have to do it assign your data source to your report in code and it should work. This even supports exporting to PDF.
Seems as no-one has mentioned Latex-based solutions, there was a stack overflow Tex question answered by jason. Short version: uses MikTex, beautiful documents, big hassle to use build/maintain.
Thanks for all your answers...
I finally decided to implement my own solution using Visual Studio 2010 and the Office-Tools... This is not the "perfect" solution, but it was easy & fast to implement, while i still have the flexibility to change the documents witch excel or word...
Downside of course: You need Office installed.
It depends on how you get your template documents. For example, if you have others in your organization responsible for generating the "standard" invoice document, you'll probably have a solution that involves mail merges in the Microsoft Word API, because you need to work with Word-formatted input files. Alternately, if you are merely given the specs for the appearance of the document ("Logo in the top-right, 5 inches down, then a horizontal line two inches below that, then... etc.") You could do it entirely in code. Even if you're designing a solution from scratch, take into account who your document suppliers WILL be, and plan accordingly. Finally, if this is from-scratch for a small set of documents that won't change much (i.e., you're starting your own software company and want to send invoices) don't do it. Just buy something off the shelf or use Word :)
We use xaml FixedPage, can use a designer like Kazaml, it has a lot of layout flexablity, and databinding works great with dynamic objects like expando. In code we bind a datacontext and then render that to XPS, since we need the final output to be pdf we use GhostXPS which is free but has to be executed in a separate processs, there are third party fully managed converters for xps to pdf though.
We use Crystal Reports which comes free with Visual Studio. You can easily create a report/document that is bound to a database or unbound.
For example you could suppress the header and footer, expand the details section to be approx. A4 size, then add either bound fields or use parameters for unbound content. Then at runtime for bound documents set the selection formula to only pull in data for one transaction or for unbound documents just pass in the parameters.
A nice feature of Crystal Reports is there are export features, so export to PDF, Word, etc. Also it's easy to auto print to a specified printer.
Crystal reports can be a pain! On a basic level the outsourced developers for our in house software for Works Order, Invoices etc we use Dev Express although I think it can be pricey.
For reports being generated by the software I ended up choosing to have exports into a raw CSV which of course can be opened up by any spreadsheet software

Choosing a cross-platform library for PDF rendering and analysis app (preferably using C#)

I am planning to write an app that can open and display PDF documents, and perform OCR on vector graphic elements within the PDFs. The user must be able to select regions of the document and I need to draw real-time annotations on the document. I don't need to alter or save the document itself.
I have plenty of experience with C# and WPF; I have written a similar application already that does the above on XPS/XAML documents rather than PDF. However that app only runs on Windows and PDF documents must be converted to XPS first.
I have done quite a bit of research and there are many, many options available, none of which seem an obvious choice. There are many libraries that can open PDFs or create PDFs, but most don't seem to give you access to individual vector graphic elements in a format that lets you draw/manipulate them on the screen (similar to what I could do with WPF graphic elements extracted from XPS documents).
I am familiar with .Net and C# (including .Net 2 GDI+ graphics) and I am very keen to stick to what I know. I am also using EmguCV for image recognition which can be compiled in Mono or .Net. As such I am looking at Silverlight (running standalone) or Mono options, both of which should run on PC and Mac.
Performance (for both graphics and number crunching) is a strong consideration, though I am just as interested in getting this up and running quickly.
Does anyone have any experience with opening PDFs, extracting vector graphic elements (perhaps as SVG) and rendering them in a Mono app? Can individual elements be rendered to bitmap?
Alternatively, does anyone have experience with opening PDFs in Silverlight and converting them to XPS or XAML at runtime? I know that WPF and Silverlight graphics libraries are not 1:1, but I'm not sure how this affects XPS contents (generally composed of Canvas, Glyphs and StreamGeometry objects).
Thank you for any advice, tips or links you have to share.
look at this
http://silverpdf.codeplex.com/
it's client side pdf reading library. actually right now it can only read files, but you could play with it and make your own "display" functionality.
You might want to examine the internals of your PDFs so you understand what they actually contain better - you might be very surprised! For example, text can often be scanned pages or images and vecotr graphics do not exist as neat little packages. We wrote a whole load of general articles about what is inside a PDF and analysis tools at http://www.jpedal.org/PDFblog which are not specific to any tool or language.

Previewing TIF documents on the Web (.Net C#)

I am looking for a way to display TIF documents on a web page. It basically needs to render a Multi-page TIF in some form of container on a web page.
Do I need a control or is there a simple way to build something like this? Is there any free stuff that we could simply implement?
I have looked at the Telerik reporting product which apparently contains a Tif viewer. I haven't looked into the licensing for this though. (If I only need the TIF Viewer, do I need to purchase the entire reporting solution?
Our biggest issue at the moment (like always) is that we have a very tight deadline with very little available resource. This product will be installed at a client so ActiveX controls that request user permission to install are less than ideal.
Any suggestions and/or comments would be welcome.
Thanks
If you want to try and roll your own (this would be a lot of work), you can use the System.Drawing namespace to convert TIF images to a browser-supported format, like PNG or JPG, or a third party library like AbcPdf to go to PDF as Lazarus suggested. The problem here is that you would have to create and code-behind a toolset for magnification, cropping, and multi-page support, along with whatever else you would want, which could be quite a bit of coding (unless you went to PDF and relied on Adobe Reader). Also, the server-side conversion can be prohibitive for speed if you're dealing with large TIF files or with formats that aren't supported.
As far as vendor solutions are concerned, I don't know of any good free viewing plugins off-hand. R Ubben is right; Snowbound's viewer is nice, but if I recall, the AJAX version requires it's own website that you pass the image to, which then gets rendered to the client, which may bring up some security issues (and leaves a bad taste in my mouth anyway). Atalasoft has an excellent AJAX image viewer and a very powerful imaging SDK, but it does cost a bit. My current company has settled on an ActiveX plugin from Pegasus Imaging (recently merged with Accusoft) called Prizm Viewer. The viewer itself is quite powerful, can handle many image formats, and is scriptable. It does have drawbacks (beyond being an ActiveX control). We've had some trouble with our desktop deployments as the default install will only push for the current user as opposed to the local machine, but we've fixed that with a post-install registry hack.
I would say that, if you have the cash and want a robust imaging solution, go with Atalasoft. Otherwise, Pegasus is fairly cheap and works just fine, unless you have severe aversions to ActiveX. There are lots of other options out there, it's just a matter of how much money you have and how much coding you want to do.
Use a library server-side to convert the TIF to a PDF (assuming that it's a common plug-in that most people have) which will eliminate the need to install another, convert each page of the TIF into a GIF or JPG and present those, again fully supported by browsers eliminating the need for an additional plug-in.
You could probably do this conversion on-the-fly and then cache the output to reduce subsequent loading times.
There's a good, free viewer that has an ActiveX version for IE and a Mozilla plugin for Firefox. Alternatiff. It's free but requires registration that's fairly painless.
# R Ubben
Thanks for mentioning our AJAX application! There is a live version of the ajax document viewing application, VirtualViewer, available at http://ajaxdocumentviewers.com and a free trial download. VirtualViewer may be overkill for simply viewing TIFF images on the web - depending on the size of your organization - so we also provide the RasterMaster SDK so you can build your own file conversion and viewing apps.
Doug
Snowbound Software has a pretty good image viewer. It does not use ActiveX. Displaying tiffs is not difficult, but sometimes you need something quick.
I've used Adeptol's AJAX Document viewer to do the same thing. Works great and easy to implement.
i'm just looking for the same..
found this:
http://www.neodynamic.com/demo-faq/imagedraw-aspnet/imagedraw-aspnet-multipage-tiff-viewer-sample.aspx
hope it can help, otherwise if you find something better, please let me know by inbox :)

How can a Word document be created in C#? [closed]

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.

Categories

Resources