简体   繁体   中英

Delphi: best way to convert rtf to text

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.

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.

The page

  • http://www.delphipraxis.net/152766-rtf-nach-html.html for some pointers to components, libraries and other sources for RTF converters, some of them include a RTF to Text conversion option.

  • ScroogeXHTML , a library for RTF to HTML / XHTML conversion, might be useful. It supports a subset of the RTF standard, and is easy to customize. It has a PlainText export format option. Note: I am the author of ScroogeXHTML for Delphi / ScroogeXHTML for the Java platform. It is a commercial product.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM