TRVReportHelper DrawPage do not draw "page header"

General TRichView support forum. Please post your questions here
Post Reply
alisichkin
Posts: 7
Joined: Fri Jul 20, 2018 8:24 am

TRVReportHelper DrawPage do not draw "page header"

Post by alisichkin »

Hello!
I use TRichView (15.1.2) and Synopse PDF engine to convert RFT file to PDF.

I use your's example:
........
procedure DrawPage(rvh: TRVReportHelper; PageNo: Integer; R: TRect);
begin
rvh.DrawPageAt(.......
end;
........

But when I try to convert file with page header/footer I get PDF file without header/footer.
In RichView code I see:
PtRVData.pas
procedure TCustomMultiPagePtblRVData.DrawSidenotes(Canvas: TCanvas;
.....
begin
SidenoteList := GetSidenoteList(PageNo);

SidenoteList - always null

How to fix it?

Alexander.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVReportHelper DrawPage do not draw "page header"

Post by Sergey Tkachenko »

TRVReportHelper does not support headers, footers, footnotes, endnotes, sidenotes and text boxes.
There are some examples using separate TRVReportHelpers for the main document and for headers and footers, but still they do not support notes, do not support all types of headers and footers, and do not support all page options.

All these problems are solved in TRichView 17:
- TRVPrint component can be used not only for printing, but also for drawing pages on any canvas. Unlike TRVReportHelper, TRVPrint supports page layout properties, header and footers, footnotes, endnotes and text boxes.
- new helper class TRVReportHelperWithHeaderFooter. It contains TRVReportHelper components representing documents with all possible headers and footers, linked to their RVStyles. It is useful for loading RTF or RVF files containing headers and footers.
- new demo projects using the features above to generate PDF using third-party libraries (in ThirdParty\Export folder), include SynPDF demo.

PS: The components supports reading header, footers, page options, footnotes and endnotes from RTF. It does not support reading text boxes (only export) and document sections.
alisichkin
Posts: 7
Joined: Fri Jul 20, 2018 8:24 am

Re: TRVReportHelper DrawPage do not draw "page header"

Post by alisichkin »

Hello!
Many thanks for the detailed answer.
Based on the examples provided by you, I wrote a function that converts RTF files to PDF.
The function works for both normal RFT files and for files with headers/footers.
Could you see at my function? Have I done everything right?

Attached:SynRTF2PDF.pas
Attachments
SynRTF2PDF.pas
(10.03 KiB) Downloaded 1338 times
alisichkin
Posts: 7
Joined: Fri Jul 20, 2018 8:24 am

Re: TRVReportHelper DrawPage do not draw "page header"

Post by alisichkin »

After more thorough testing, I find errors for files for which headers/footers were specified - only on the last, or on the first and last page.
How to fix it?

Alexander.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVReportHelper DrawPage do not draw "page header"

Post by Sergey Tkachenko »

RTF document may have headers for the first page, for even pages, and for the rest of pages, totally 6 headers/footers.
SetHeader and SetFooter methods have the second optional parameter defining which header/footer is assigned.

So you need to create not 2 but 6 report helpers for headers and footers.

Also, RTF file may contain headers and footers that should not be displayed.
Assign rvh.RichView.RTFReadProperties.ReadDocParameters = True to load page properties from RTF into rvh.RichView.DocParameters.
TitlePage instructs to show/hide first page header and footer.
FacingPages instructs to show/hide even page header and footer.

Next, CalcPageLayout must be modified, to calculate layouts for the first page, odd pages, even pages.
rvh.Init must be called one time after all page layouts are calculated, and rvh.FormatNextPage must be called not with the same PageHeight parameter for all pages, but with PageHeight parameters corresponding to the proper page.

---
I think it's simpler to upgrade and use TRVPrint.VirtualPrinter instead :)
alisichkin
Posts: 7
Joined: Fri Jul 20, 2018 8:24 am

Re: TRVReportHelper DrawPage do not draw "page header"

Post by alisichkin »

Thank you for our answer!
I work for a company that creates a Medical Information System.
The system has been working for more than a decade and a large number of programmers took part in its writing. The RichView component is redesigned to meet our needs. In this regard, I'm not sure that the update will be a simpler solution :roll: .

Correctly I realized way that get the header/footer?:

var
rvh: TRVReportHelper;
rvhHeader: TRVReportHelper;
rvhFooter: TRVReportHelper;
rvhFirstPageHeader, rvhFirstPageFooter: TRVReportHelper;
rvhEvenPagesHeader, rvhEvenPagesFooter: TRVReportHelper;
IsFirst: Integer;
IsEven: boolaen;
.................
rvh.RichView.RTFReadProperties.SetHeader(rvhHeader.RichView.RVData, rvhftNormal);
rvh.RichView.RTFReadProperties.SetHeader(rvhFirstPageHeader.RichView.RVData, rvhftFirstPage);
rvh.RichView.RTFReadProperties.SetHeader(rvhEvenPagesHeader.RichView.RVData, rvhftEvenPages);
.................

IsFirst := i=1;
IsEven := not Odd(i);
.................

function GetDocHeader: TRVReportHelper; overload;
begin
Result := nil;
// First page
if rvh.RichView.DocParameters.TitlePage and IsFirst and
(rvhFirstPageHeader.RichView.ItemCount>0)
then
Result := rvhFirstPageHeader
else
// Even page
if rvh.RichView.DocParameters.FacingPages and IsEven and
(rvhEvenPagesHeader.RichView.ItemCount>0)
then
Result := rvhEvenPagesHeader
else
// Default header
if rvhHeader.RichView.ItemCount>0 then
Result := rvhHeader
end;
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVReportHelper DrawPage do not draw "page header"

Post by Sergey Tkachenko »

Yes, this code looks correct.
You should take into accout that all headers and footer.s may have different height. Tops of all headers (and bottoms of all footers) are the same, but bottoms of headers (and tops of footers) may be different because of different heights, and it affects heights of the main document.
You now read DocParameters from RTF. They have not TitlePage and FacingPages, but also margins, header and footer y, MirrorMargins. You can take them into account.
Post Reply