Hi folks,
i'm experimenting some methods to calculate the rtf text height for printing and cutting the rtf for a pagebreak to the next page.
Example: I'm having a rectangle of 150px * 50px on page 1 and a random rtf text which should be printed in the rectangle, but if the height is higher than 50px it should print all that fit in the rectangle and giving a carret position to print the rest on page 2.
Possible calculation: I'm calculating the height of every paragraph and compare if it fit in the rectangle. If its not fit, then i know there must be a pagebreak.
I know there must be a function for that but i haven't found it directly.
Tahnks for help,
greetings ThYpHoOn
Height of a Row/Paragraph to calculate for printing
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Paragraph size is known only when it is already formatted for printing (if you use RVPrint, when RVPrint.FormatPages is called).
Sorry, I do not understand what you want to implement. Very probably, there is a simple solution for you problem, without paragraph size calculation.
For example, if you need printing in 150x50px, you can define this size in RVReportHelper (Init(...150...), FormatNextPage(...50...)).
Sorry, I do not understand what you want to implement. Very probably, there is a simple solution for you problem, without paragraph size calculation.
For example, if you need printing in 150x50px, you can define this size in RVReportHelper (Init(...150...), FormatNextPage(...50...)).
Thanks Sergey, this looks good.
Where could i get the carret-position if it not fit into one page?
Here is an snip of my code:
Where could i get the carret-position if it not fit into one page?
Here is an snip of my code:
Code: Select all
function CalcRTFText (const cRTF:String; const nHeight:Integer; const nWidth:Integer; var nPos:Integer):String;
var rvh : TRVReportHelper;
oStream : TStringStream;
begin
rvh := TRVReportHelper.Create(NIL);
oStream := TStringStream.Create(cRTF);
rvh.Richview.LoadRTFFromStream(oStream);
rvh.Init(Printer.Canvas,nWidth);
if not(rvh.FormatNextPage(nHeight)) then begin
//if (rvh.PagesCount = 1) then
nPos := 0;
Result := cRTF; //the full input rtf is the result, because all fit
end else begin
// here i need the carret-position (nPos)
end;
//Freeing Memory
FreeAndNil(oStream);
FreeAndNil(rvh);
end;
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
RVReportHelper.GetFirstItemOnPage returns the position at the beginning of the page. However, the page must be formatted, so I suggest to call FormatNextPage until the whole document is formatted, then use GetFirstItemOnPage.
And, if you use tables, there is no such thing as caret position at the beginning of page. Because page break may cross several cells.
And, if you use tables, there is no such thing as caret position at the beginning of page. Because page break may cross several cells.
Which function should i use for the RTF-Text that didn't fit on the first page?
I've got the ItemNo and offset with
But how could i use this information to get the rtf-text at this point?
I've got the ItemNo and offset with
Code: Select all
rvh.GetFirstItemOnPage(2,nItemNo,nOffset);
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Do you want to get text after this point?
Then select and save selection:
rv.SetSelectionBounds(nItemNo, nOffset, rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1));
rv.SaveRTFToStream(Stream, True);
Unfortunately, you cannot select in TRVReportHelper, so you need a copy of this text in TRichView.
Besides, TRVReportHelper can save text in a page in RVF format: rvh.SavePageAsRVF(Stream, PageNo).
Then select and save selection:
rv.SetSelectionBounds(nItemNo, nOffset, rv.ItemCount-1, rv.GetOffsAfterItem(rv.ItemCount-1));
rv.SaveRTFToStream(Stream, True);
Unfortunately, you cannot select in TRVReportHelper, so you need a copy of this text in TRichView.
Besides, TRVReportHelper can save text in a page in RVF format: rvh.SavePageAsRVF(Stream, PageNo).
-
- Site Admin
- Posts: 17555
- Joined: Sat Aug 27, 2005 10:28 am
- Contact: