Page 1 of 1
Load docx header and footer
Posted: Thu Nov 16, 2023 5:47 pm
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
Re: Load docx header and footer
Posted: Fri Nov 17, 2023 8:45 am
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.
Re: Load docx header and footer
Posted: Fri Nov 17, 2023 11:32 am
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
Re: Load docx header and footer
Posted: Fri Nov 17, 2023 3:17 pm
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
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.
Re: Load docx header and footer
Posted: Fri Nov 17, 2023 4:20 pm
by rdevine
Perfect thank you! I'd assumed that SetHeader was for printing/saving only.
Cheers, Bob
Re: Load docx header and footer
Posted: Fri Nov 17, 2023 7:48 pm
by Sergey Tkachenko
TRichView.SetHeader and SetFooter are for loading and saving files (RVF, RTF, DocX).
TRVPrint.SetHeader and SetFooter are for printing.