0

im puzzeling this for a while and yet did not found any solution that might work for me on the net.

Im having a given RTF File (from outlook 2010) that contains (as seen from windows Apps like Outlook or Word) several special keyWords all over the document which i would like to replace or "substitute" with my own content. so i like a rtf template file and take that to make a copy it it with the keyWords replaced.

the rtf files are "cp1252" encoded if i am right.

the "keywords" that are supposed to be replaced within the rtf file are of format

{xx:word} where xx is a number and word is a single word.

now if i look at the rtf template file it seems that "sometimes" the '{' is just beeing 'escaped' as '{' (same with '}') and sometimes its not found at all or is somehow "encoded" in some strange way. so it seems i am unable to do a "simple String replacement" .

but i would like to do just that! Something more "high level" so i dont need to care about "bytes" and weird internal character encodings while i search and replace that keyword strings.

Is there something i can use that takes away the pain of handling rtf content and lets me just do it without knowing rtf internals and without destroying formating and structure of the rtf file ?

thanks for any help! Axel

Axel Werner
  • 186
  • 1
  • 17
  • Can you use a library? http://stackoverflow.com/questions/17223903/java-rtf-parser – Andy Turner Oct 07 '15 at 14:02
  • More of a hack, but I was able to just read it into a StringBuilder and run replaces on the keywords and then write it out to a new file. Sometimes rtf markup would get stuck in the middle of our tags that we were replacing for the merge and we would have to mess with the template to fix it so that the replace would work properly. – Paul Zepernick Oct 07 '15 at 14:06
  • Andy, will need to test it. i already did read this question though , but it didnt appeared to me as something that helps me much. but i will recheck today and do some testing with it. – Axel Werner Oct 09 '15 at 06:16
  • hmm itext seems to have rtf stuff removed if im not mistaken. - still not found a proper library/framework to parse, modify and rebuild rtf. :/ – Axel Werner Oct 09 '15 at 12:10

0 Answers0