TRVPageNumberItemInfo

General TRichView support forum. Please post your questions here
Post Reply
grizw
Posts: 4
Joined: Tue Aug 17, 2021 8:47 pm

TRVPageNumberItemInfo

Post by grizw »

Dear Sergey

First let me congratulate you on the extraordinary amount of work you have done on TRichView and associated components.

The Demos are very useful but I am struggling to find any simple example of creating a basic footer with a page number embedded, like 'Page {p}'. I understand that a TRichView document can be created and a footer applied using SetFooter. There is reference in the help to TRVPageNumberItemInfo. Why is this code failing?

...
1 TRVPageNumberItemInfo *pg;
2 TRVScreenAndDevice scrdv;
3 pg->CreatePrintingDrawItem(RichView2->RVData, RVStyle1->ParaStyles, scrdv, 500);
...
footrv->AddItem(L"Page ", pg);

This compiles, RichView2 and RVStyle1 are dropped on the main form. It crashes on line 3 with EAccessViolation. There is no Create() method for TRVPageNumberItemInfo only CreatePrintingDrawItem.

What does the string parameter in AddItem do?


FYI There are references in the Forums to sybrex dot com. This URL appears dangerous and certainly has nothing to do with LLPDFLib these days.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVPageNumberItemInfo

Post by Sergey Tkachenko »

When you populate a document, you add items.
Drawing items are used internally (one (or more) drawing item defines the position and size of one item).
Drawing items are created when you call RichView->Format(). Never create or add a drawing item yourself.

The code for adding a page number:

Code: Select all

TRVPageNumberItemInfo* pg = new TRVPageNumberItemInfo (footrv->RVData);
pg->TextStyleNo = 0; // index in the collection footrv->Style->TextStyles
pg->ParaNo = 0; // index in the collection footrv->Style->ParaStyles, or -1 to continue paragraph
footrv->AddItem("", pg);
grizw
Posts: 4
Joined: Tue Aug 17, 2021 8:47 pm

Re: TRVPageNumberItemInfo

Post by grizw »

Thank you. That code compiles and runs but the footer I created and the background image I set in RichView1 options do not appear in the file created by SaveRTF

The background shows in the TRichView component on the form when the app runs. I wasn't expecting the footer to show there (should it?) but it is very important that the generated RTF file contains the footers and the background. How do I do that? RTF may not support background images but it certainly supports footers.

TRichView *footrv = new TRichView(Application);
TRVPageNumberItemInfo* pg = new TRVPageNumberItemInfo (footrv->RVData);
pg->TextStyleNo = 0; // index in the collection footrv->Style->TextStyles
pg->ParaNo = 0; // index in the collection footrv->Style->ParaStyles, or -1 to continue paragraph
footrv->AddNL(L"Page",0,0);
footrv->AddItem(L"", pg);
footrv->Format();
RichView1->AddNL("Some text", 1, 1);
RichView1->Format();
RichView1->SaveRTF(L"test.rtf", false);
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVPageNumberItemInfo

Post by Sergey Tkachenko »

To save headers and footers in RTF, include rvrtfSaveHeaderFooter in RTFOptions.

Sorry, TRichView cannot save background images in RTF. Actually, RTF does not support page images, but it can contain a shape object linked to page placed on a background.
TRichView can only save a background color as a rectangle shape, but cannot load it. And it cannot save and load background image in RTF.
grizw
Posts: 4
Joined: Tue Aug 17, 2021 8:47 pm

Re: TRVPageNumberItemInfo

Post by grizw »

Thank you.
1. I have seen the demo for opening an RTF file and saving to PDF. Is there any demo code for saving the RichView object with the graphics, formatted text and footer/header directly to PDF using LLPDFLib?
2. Would this allow for a background graphic?
3. PDFs use Metafiles so it seems counterproductive to draw and save to PDF as a bitmap. Can one draw on a TMetaFile canvas and then add that to the RichView object and save to pdf?
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVPageNumberItemInfo

Post by Sergey Tkachenko »

The demo for PDF export using LLPDFLib can be found in TRichView installation, in the folder
<TRichView Dir>\ThirdParty\Export\LLPDFLib\Demos\RV2PDF\

LLPDFLib's TPDFDocument provides a canvas for drawing PDF pages.
AFAIK, internally, this is a mefafile canvas, so all drawing is recorded to a metafile, then TPDFDocument converts metafile commands to PDF commands.

Drawing is performed using TRVPrint component in "virtual printer" mode, i.e. in the mode where it can draw pages on any canvas instead of a real printer.
A document, including headers and footers, is stored in TRVReportHelperWithHeaderFooters object.
grizw
Posts: 4
Joined: Tue Aug 17, 2021 8:47 pm

Re: TRVPageNumberItemInfo

Post by grizw »

grizw wrote: Thu Aug 19, 2021 1:48 am Thank you. That code compiles and runs but the footer I created and the background image I set in RichView1 options do not appear in the file created by SaveRTF

The background shows in the TRichView component on the form when the app runs. I wasn't expecting the footer to show there (should it?) but it is very important that the generated RTF file contains the footers and the background. How do I do that? RTF may not support background images but it certainly supports footers.

TRichView *footrv = new TRichView(Application);
TRVPageNumberItemInfo* pg = new TRVPageNumberItemInfo (footrv->RVData);
pg->TextStyleNo = 0; // index in the collection footrv->Style->TextStyles
pg->ParaNo = 0; // index in the collection footrv->Style->ParaStyles, or -1 to continue paragraph
footrv->AddNL(L"Page",0,0);
footrv->AddItem(L"", pg);
footrv->Format();
RichView1->AddNL("Some text", 1, 1);
RichView1->Format();
RichView1->SaveRTF(L"test.rtf", false);
Thanks Sergey but I have rvrtfSaveHeaderFooter in RTFOptions for RichView1 checked and it still does not save anything in the RTF file. Is this because I have to set this options for footrv? I tried
footrv->RTFOptions = RichView1->RTFOptions;
which compiles but does not make a difference. I tried
TRVRTFOptions top;
top << rvrtfSaveHeaderFooter;
footrv->RTFOptions = top;
but all I get is
{\rtf1\fbidis\ansi\ansicpg0\uc1\deff0\deflang0\deflangfe0{\fonttbl{\f0\fnil Arial;}{\f1\fnil Times New Roman;}}{\colortbl;\red0\green120\blue215;\red0\green0\blue0;\red0\green128\blue0;\red128\green0\blue0;\red255\green0\blue0;}


\pard\fi0\li0\qc\ri0\sb0\sa0\itap0 \plain \f1\b\fs20\cf1 Some text\par}

Help please.
Last edited by grizw on Wed Sep 15, 2021 11:08 pm, edited 1 time in total.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVPageNumberItemInfo

Post by Sergey Tkachenko »

This option must be set for TRichView/TRichViewEdit that contains the main document.
If it does not work, please create a simple project reproducing the problem and send it to me (email richviewgmailcom)
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: TRVPageNumberItemInfo

Post by Sergey Tkachenko »

I received your test project.
Changes to fix it:

Code: Select all

                footrv->Style = RichView1->Style;
                RichView1->SetFooter(footrv->RVData);
Also, before formatting footrv, its parent must be assigned.
Post Reply