Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi: best way to convert rtf to text

Tags:

delphi

rtf

I need to convert rtf to plain text. i used to write a function that strips away rtf headers but it is never perfect.

So one option can be using a TRichEdit created at runtime (something like described here but done of course at runtime). But is there another way? Is there an rtl function for this or a better approach?

UPDATE:

In this question I wrote the final version of my rtf to text procedure.

like image 231
LaBracca Avatar asked Jul 09 '10 15:07

LaBracca


People also ask

How do I convert RTF to TXT?

Convert the RTF file to a text file using a word processor. To do this, first open the file in a program such as Microsoft Word or OpenOffice Writer. Select the “Save as” command in the File menu, choose the TXT format in the drop-down menu and click “Save.”

How do I convert RTF to DOC?

Find a desired location to save the file. From within the Save As Window, find the Save File Type field. Select the drop-down arrow, and change the file from Rich Text Format (rtf) to Word Document (doc). Select Save.


1 Answers

If you really want to find a way of doing this conversion you should take a look at how the class TConversion is implemented in the class TRichEditStrings. These classes are in ComCtrls.pas. By understanding how the conversion is done inside the RichEdit controls you may be able to write your own.

However, looking at the practical aspects of implementing this and not knowing what the performance requirements are for your question I would go for the TRichEdit conversion approach outlined in your link.

like image 138
Alan Fletcher Avatar answered Nov 15 '22 01:11

Alan Fletcher