Load docx header and footer

General TRichView support forum. Please post your questions here
Post Reply
rdevine
Posts: 16
Joined: Wed Apr 05, 2006 8:27 am

Load docx header and footer

Post by rdevine »

I can't see how to load a docx header or footer into a TRichViewEdit from a file - is it possible? I can see how to define a header and footer and save them to a new docx, but I need to be able to re-open the docx file for further editing.

Thanks, Bob
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Load docx header and footer

Post by Sergey Tkachenko »

TRichViewEdit cannot store headers and footers, so you need additional TRichViewEdits or TRVReportHelper components to store them.
(although the main document and headers/footers are stored in different editors, it is still possible to print them all correctly using TRVPrint, and save to RTF/DocX/RVF)

The key methods are SetHeader and SetFooter.

See the demos:
1) in TRichView\Demos\DelphiUnicode\Assorted\Printing\Headers\ - it has one TRichViewEdit for the main document, and also TRichViewEdit for each header and footer
2) in ThirdParty\Demos\Export\. These demos load RTF/DocX/RVF file (that may contain headers and footers) and save as PDF, using various third-party PDF libraries. They use TRVReportHelperWithHeaderFooters component to store document with headers and footers. The demos cannot edit the document but display it using TRVPrintPreview.

Another alternative is using ScaleRichView. It can store and display everything in a single component, TSRichViewEdit.
rdevine
Posts: 16
Joined: Wed Apr 05, 2006 8:27 am

Re: Load docx header and footer

Post by rdevine »

Sorry Sergey my question was a bit unclear. I'm aware I need separate TRichViewEdit instances for the header and footer and exporting is also understood. My problem is in extracting the header and footer of a docx during import in order to populate the header/footer TRichViewEdits.

I've had a look through the RVDocXReader source and can see LoadHeaderFooter and the OnHeaderFooter event, but some code showing how to use them would be great.

Thanks, Bob
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Load docx header and footer

Post by Sergey Tkachenko »

Sorry, I do not understand.

If you have RVMain and RVHeader: TRichViewEdit, and call

Code: Select all

RVMain.SetHeader(RVHeader.RVData, rvhftNormal)
then, when you call

Code: Select all

RVMain.LoadDocX(FileName)
RVMain will receive the main DocX document, and RVHeader will receive the header from DocX.

No need to call special methods or process any events.
rdevine
Posts: 16
Joined: Wed Apr 05, 2006 8:27 am

Re: Load docx header and footer

Post by rdevine »

Perfect thank you! I'd assumed that SetHeader was for printing/saving only.

Cheers, Bob
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Load docx header and footer

Post by Sergey Tkachenko »

TRichView.SetHeader and SetFooter are for loading and saving files (RVF, RTF, DocX).
TRVPrint.SetHeader and SetFooter are for printing.
Post Reply