Copy content between documents (preserve formatting)

Hi,
Can i copy content from one document to another and still preserve the formatting of source text?
I have an input rtf file Input.rtf with below content
------------------------------------------
Microsoft Word editor comes with cool features. Aspose Word library helps programmers in automating Word formatting.
Prepared by Prasanth
--------------------------------------------
I have a placeholder document where i need to replace the content from Input.rtf. The <%TITLE%> has to be replaced with “Sample document” and the <%CONTENT%>
The content of Placeholder.doc is
<%TITLE%>
<%CONTENT%>
-------------------------------------------------
Can i replace the placeholders (enclosed in <% and %>) in the Placeholder.doc with the corresponding values from Input.rtf and preserve the formatting (Bold, Italics, Alignment etc). The desired output is (please note the formatting in the below text)
Sample document
Microsoft Word editor comes with cool features. Aspose Word library helps programmers in automating Word formatting.
Prepared by Prasanth
(I tried the replace function with
Regex regex = new Regex(@"(?.*?)")
and ReplaceEvaluator.Match.Groups("tag").value
Need help to copy the formatted text from input file.
regards
Prasanth

Hi
Thanks for your inquiry. I think that you can achieve this using ReplaceEvaluator. For example see attached documents and code.
Best regards.

Thanks, the code worked. However when i modified the TITLE in the inpout text to
instead of
Sample Document
the code snippet generated a NULL pointer exception. This is quite resonable since the and Sample document will come under the same paragraph (based on my understadning of WML specification). As I understood from the Aspose user manual, the object model in Aspose closely matches with the WML specification. So i should look beyond a paragraph to extract the TITLE from the modified Input rtf, right?

Hi,
Here is another observation on the copy operation. I saved “in.doc” as “in.rtf” from Word. With the input document in the rtf format, I received a different output (The TITLE value is not copied to out.doc, and a new line is missing in the CONTENT value). We are using rtf as the input in our application. Do we need a different logic to process rtf files? Can you help with this. (Attaching the sample files used in my test application)
regards
Prasanth

Hi
Thank you for your inquiry. No, you should use the same logic for proccessing doc and rtf files.

  1. In the logic that I use in the attached code , , and tags should be placed in the separate paragraphs. See attached in.rtf.
  2. It seems that new line that you were talking about is line spacing. This is known issue. We will notify you as soon as it is done.
    Issue #4106 – Line spacing is changed after open/save RTF document.

Best regards

We have released a new version of Aspose.Words that contains a fix for this issue.

Issue #4106 - Line spacing is changed after open/save RTF document.

The new version of Aspose.Words is available for download from here.
Best regards.