Page 2 of 2
Posted: Tue Jun 07, 2011 6:31 pm
by jonjon
OK Sergey, I'll wait. Thanks.
Posted: Sun Oct 30, 2011 12:11 pm
by Sergey Tkachenko
In DOC/RTF file, PAGEREF is a reference to a bookmark. When generating TOC, MS Word adds a hidden auto-maintained bookmark before each heading.
I can add checkpoints before each heading when generating TOC. However, they will not be hidden or auto-maintained, they will be like any other checkpoints. If it's ok, I'll make an example.
Posted: Sun Oct 30, 2011 12:27 pm
by jonjon
Sergey,
Thank you for taking the time to review my question. I already have added checkpoints (bookmarks) before each heading. However the difficult part for me is to update the TOC generation so that the page number displayed is a reference to those bookmarks and not a static page number, when exported to RTF. An example would be very welcome.
John.
Posted: Sun Oct 30, 2011 4:52 pm
by Sergey Tkachenko
This unit contains code for generation TOC for RTF:
It contains the same functions as the original version, with the same parameters.
Differences:
- new functions add checkpoints before each heading in the document;
- new functions insert RTF fields "PAGEREF" in place of page numbers.
There are 2 main ways for insertion RTF codes using TRichView:
1) using text with a style having rvteoRTFCode in Options;
2) using some control and processing OnSaveComponentToFile.
This example uses the first method. Its disadvantage: in TRichView, you can see all these codes directly in text.
The functions still require formatted document, because they calculate page numbers that will be displayed in MS Word when you load this document initially. You still need to select TOC paragraphs in Word and press F9 to update page numbers.
The code for calculating initial values of page numbers could be removed (they can be displayed initially, as, for example, '?'), it would simplify the code.
Update:
2018-Apr-18: for compatibility with TRichView 17.3; the margins problem in the RVReportHelper version is fixed.
Old version:
http://www.trichview.com/support/files/rvtocrtf.zip - for TRichView 17.2 and older
Posted: Mon Oct 31, 2011 1:28 pm
by jonjon
This is exactly what I needed, thank you very much Sergey!
Small problem in TOC generation
Posted: Mon Oct 27, 2014 5:41 pm
by SculptureEK
The number of pages of the Table of Contents is not correctly calculated IF
- the margins of the RichView are greater than the default margins AND
- there is a TOC line which is just a bit too large to fit in 1 line AND
- because of this line we need a 2nd page for the TOC
Obviously, the RichView used to build the TOC thinks that the TOC fits in 1 page while it needs 2 pages in fact.
It works with this change in function AddTableOfContents (TRVReportHelper overload):
// building TOC in RVReportHelper2, calculating TOCPageCount
RVReportHelper2.RichView.Style := RVReportHelper.RichView.Style;
ADD-> RVReportHelper2.RichView.LeftMargin := RVReportHelper.RichView.LeftMargin;
ADD-> RVReportHelper2.RichView.RightMargin := RVReportHelper.RichView.RightMargin;
RVReportHelper2.RichView.AddNL(Title, TitleStyleNo, TitleParaNo);
Kind regards,
Hans
Posted: Tue Oct 28, 2014 1:24 pm
by Sergey Tkachenko
You are right, margins must by copied from RVReportHelper to RVReportHelper2, all 4 margins
Update 2018-Apr-18: this fix is included in the unit.
Re: [Unit] Adding a table of contents
Posted: Wed Apr 18, 2018 12:22 pm
by Sergey Tkachenko
I updated the demos for compatibility with
TRichView 17.3
Here is a brief overview of available "table of context demo projects":
1. Adding TOC in TRichView, pages are calculated according to TRVPrint settings. Alternatively, adding TOC in TRVReportHelper, using the specified PageWidth and PageHeight:
http://www.trichview.com/forums/viewtop ... 787#p15121
How to use:
http://www.trichview.com/forums/viewtop ... 122#p15122
2. Adding TOC containing RTF codes in place of page numbers. If you save this document in RTF, open in MS Word and update fields, references to pages will be added in these places:
http://www.trichview.com/forums/viewtop ... 373#p20373 (before updating fields, MS Word will display page numbers calculated by TRichView).
This unit is used exactly like the previous unit.
3. A special item type that does not build a TOC itself, but, if exported to RTF or DocX, inserts a TOC code. When MS Word updates this field, it builds a TOC itself. This item was initially introduced here:
http://www.trichview.com/forums/viewtop ... f=3&t=7034 , but now it is included in TRichView unit as <TRichView Dir>\TRichView\Source\RVTOCItem.pas.
Like any other non-text object, it is inserted using AddItem or InsertItem methods.
Since this item does not build TOC itself but simply generates RTF/DocX code, it is universal, you can insert it in TRichView, TRVReportHelper or in a ScaleRichView editor.
4. ScaleRichView version of TOC is in <TRichView Dir>\SRVControls\Demos\DocViewer\
Initially, it was almost an exact copy of #1, it just calculated page numbers in TSRichViewEdit. But in one of recent updates, we added new features:
- TOC items may be hyperlinks
- TOC may be built without page numbers
(for example, hypertext TOC is useful for HTML export)