[Demo] Convert RTF to DocX (keeping headers and page information)
Posted: Wed Aug 26, 2020 3:56 pm
With TRichView, converting RTF to DocX is simple:
Some property settings are needed to specify loading and saving page information (page size, margins, etc.) and document properties (author, title, etc.)
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}.
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}.