We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mass Document convertion project

I have been asked what it would take to convert a bunch of rtf templates to use aspose.word instead of the existing solution. About 3000 or so rtf template files.

I am wondering do you have for example a power toy or similar code that would help batch convert the existing rtf templates into C# code. The goal of the generated code is that could be compiled to generate the document as it was read in originally or as reasonably close as possible result. I am looking for something just to save grunt work of converting the templates into C# by hand.

The goal would be to save time in an area which I think is possible to automate. I would have to touch the generated code to finish the conversion but would cut down on the time spent on the simple tedious issues. Its currently not feasible to just have Aspose.word read in the original templates and make all the changes them on the fly.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. You can perform conversion in the loop. For example see the following code:

//Get list of RTF files in the directory

string[] files = Directory.GetFiles(@"C:\Temp\", "*.rtf");

//Loop through all files and conver them to DOC

foreach (string fileName in files)

{

//Open document

Document doc = new Document(fileName);

//Save document

doc.Save(Path.ChangeExtension(fileName, ".doc"));

}

Hope this helps.

Best regards.

Not exactly what I am looking for. What I am looking for is to convert the rtf version of the documents into a C# class file for each template. This C# class files would be using the Aspose.Word.Builder object class to build the documents from scratch using only code without access to the original template, which will be later merged into a class library.

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. I think you should use DocumentVisitio to achieve this. Hovwever there is no simple way to achieve such conversion.

Please follow the link to learn more about DocumentVisitor:

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/extracting-document-elements.html

Best regards.

I do not think it is possible/feasible to make a conversion from a Document into C# code that generates such document.

The reason for this is that Aspose.Words does not expose original collections of formatting attributes in the public API, but allows access to only fully calculated values.

What I mean is that in the original document you can have styles, paragraphs and runs and each element basically has a collection or formatting attributes. If you are familiar with WordML or OOXML you know rPr, pPr and so on. These collections are internally maintained by Aspose.Words but never made public directly.

Instead, Aspose.Words provides access to "fully calculated" formatting on objects.

Elements in Word documents "inherit" formatting from each other in certain (sometimes quite complicated) ways. For example, full formatting of a run of text consists of direct formatting applied to the run, run's character style, all based on character styles of that style, then character formatting of the paragraph style of the parent paragraph and all based on paragraph styles. If the run is in a table then table styles can come into play too.

For example, if you define Bold somewhere in the styles then using Run.Font.Bold will give you true. You could not have that if you only have access to plain attribute collections.

So in Aspose.Words you have access to full calculated formatting, but you don't have access to original attribute collections.

But in your case you actually need original attribute collections.If you use full formatting provided by Aspose.Words you will have no way of knowing where the formatting comes from. From a style or from an object itself. You will end up having to write ALL formatting attributes for EVERY element in the document. This will look quite ugly.

So my advice for today - don't do this with Aspose.Words. We might provide access to original attribute collections in the public API in the future, but we don't have a timeframe for this.

I would suggest you just embed your RTF templates as resources and then use Aspose.Words to load them, modify and output the way you want them.