4

Maybe this is a dumb question, but I don't get it so appologize :)

I have an RTF document, and I want to change it. E.g. there is a table, I want to duplicate a row and change the text in the second row in my code in an object-oriented way.

I think pyparsing should be the way to go, but I'm fiddling around for hours and don't get it. I'm providing no example code because it's all nonsense I think :/

Am I on the right path or is there a better approach?

Anyone did something like that before?

Santosh Kumar
  • 26,475
  • 20
  • 67
  • 118
Florian Lagg
  • 751
  • 2
  • 8
  • 21

1 Answers1

3

RTFs are text documents with special "symbols" to create the formatting. (see - http://search.cpan.org/~sburke/RTF-Writer/lib/RTF/Cookbook.pod#RTF_Document_Structure It seems that perl has a good RTF library though), so yes, PyParsing is a good way to go. You have to learn the structure and then parse (there are perl code examples in the page i mentioned. If you are lucky you can translate them in python with some effort)

There is a basic RTF module available for python. Check - http://pyrtf.sourceforge.net/

Hope that helps you a little.

SRC
  • 2,123
  • 3
  • 31
  • 44
  • two other resources : http://stackoverflow.com/questions/1337446/is-there-a-python-module-for-converting-rtf-to-plain-text http://stackoverflow.com/questions/3278850/doc-rtf-and-txt-reader-in-python – SRC Aug 10 '12 at 10:18
  • yea I saw the pyRtf and I think it doesn't fit. 'bout pyparsing ... do you know some easy understandable examples with a bit more than 'hello, world!'? For RTF I found the official Microsoft description - it's fairly easy but a bit vague. E.g. table rows could end with "\row" or with "\row \pard" which is a bit confusing, but I would handle that. What I really don't get is the concept of pyparsing. – Florian Lagg Aug 10 '12 at 11:38
  • 1
    Think I will order this: http://my.safaribooksonline.com/book/programming/python/9780596514235 – Florian Lagg Aug 10 '12 at 11:44
  • 1
    Have seen you this page? it has a lot of example for pyparsing : http://pyparsing.wikispaces.com/Examples Also, the book you have mentioned is the official book for pyparsing. So, i guess it will be a good reading – SRC Aug 10 '12 at 13:52
  • I'm marking the above as solution, as it gives the right hints. However, for me personally I found a better solution using odf-files and zipfile. Thank you all! – Florian Lagg Oct 03 '12 at 11:59