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
Load docx header and footer
-
- Site Admin
- Posts: 17602
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Load docx header and footer
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.
(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
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
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
-
- Site Admin
- Posts: 17602
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Load docx header and footer
Sorry, I do not understand.
If you have RVMain and RVHeader: TRichViewEdit, and call
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.
If you have RVMain and RVHeader: TRichViewEdit, and call
Code: Select all
RVMain.SetHeader(RVHeader.RVData, rvhftNormal)
Code: Select all
RVMain.LoadDocX(FileName)
No need to call special methods or process any events.
Re: Load docx header and footer
Perfect thank you! I'd assumed that SetHeader was for printing/saving only.
Cheers, Bob
Cheers, Bob
-
- Site Admin
- Posts: 17602
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: Load docx header and footer
TRichView.SetHeader and SetFooter are for loading and saving files (RVF, RTF, DocX).
TRVPrint.SetHeader and SetFooter are for printing.
TRVPrint.SetHeader and SetFooter are for printing.