[Demo] Convert RTF to DocX (keeping headers and page information)

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

[Demo] Convert RTF to DocX (keeping headers and page information)

Post by Sergey Tkachenko »

With TRichView, converting RTF to DocX is simple:

Code: Select all

rv.Clear;
rv.LoadRTF(InputFileName);
rv.Format; // necessary if the document contains tables
rv.SaveDocX(OutputFileName, False);
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}.
Attachments
RTFtoDocX.zip
(1.73 KiB) Downloaded 4324 times
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by jgkoehn »

Greetings Sergey,
I would be interested in how to bring in the DocX do I need a special component?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by Sergey Tkachenko »

Sorry, I do not understand the question.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by jgkoehn »

But with minor modifications, it can convert DocX to RTF,
Does this mean that DocX import is available? If so how does one do it?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by Sergey Tkachenko »

DocX import is not yet available (I corrected the text).
It is in development, you can expect it in this autumn.
jgkoehn
Posts: 303
Joined: Thu Feb 20, 2020 9:32 pm

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by jgkoehn »

No pressure just checking on the Docx progress. Any news? Thanks sir!
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by Sergey Tkachenko »

It will be released in this month.
Zevine
Posts: 1
Joined: Mon Feb 18, 2019 11:30 am

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by Zevine »

Does this mean that DocX import is available? If so how does one do it?
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demo] Convert RTF to DocX (keeping headers and page information)

Post by Sergey Tkachenko »

Yes, DocX import is available (for Delphi 2009 and newer). There are LoadDocX and LoadDocXFromStream methods.
Details are here: https://www.trichview.com/forums/viewto ... 885#p38885
Post Reply