Code: Select all
rv.Clear;
rv.LoadRTF(InputFileName);
rv.Format; // necessary if the document contains tables
rv.SaveDocX(OutputFileName, False);
However, TRichView can store only the main document, without headers and footers. So headers and footers will be lost on conversion.
There are several solutions for this problem.
1. Using TSRichViewEdit from ScaleRichView. ScaleRichView editor can contain both the main document and headers/footers in a single component, so it can load and save them.
2. Create separate TRichView, TRichViewEdit, or TRVReportHelper components for each header and footer. This approach is used in the demo <TRichView Dir>\TRichView\Demos\DelphiUnicode\Assorted\Printing\Headers\
(or identical projects for C++Builder and Lazarus).
This demo projects uses TRichViewEdit for the main document, and for 6 headers and footers.
3. Using TRVReportHelperWithHeaderFooters.
This approach is used in the attached demo.
This project converts RTF to DocX. But with minor modifications, it can convert any of {RTF, RVF} to {RTF, DocX, RVF}.