RTF page orientation and PageSize

General TRichView support forum. Please post your questions here
Post Reply
Tomas
Posts: 8
Joined: Tue Nov 22, 2005 1:57 pm

RTF page orientation and PageSize

Post by Tomas »

Hello,

Does anyone know to read RTF page orientation(Portrait, Landscape) and Page Size(A4, A3, Letter) which is loaded in TRichView?

Regards,
Tomas
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

In the current version, reading these RTF properties is not possible (without modification of source code)
Tomas
Posts: 8
Joined: Tue Nov 22, 2005 1:57 pm

Post by Tomas »

So I need to read these constant by myself before loading RTF to TRV. Maybe you have demo how to do it?
Markus D.
Posts: 11
Joined: Mon Sep 05, 2005 7:33 am

Post by Markus D. »

Hello Tomas!

Try
change sources
-----------------------------------------------------------------------------
RVRTFProps.pas

procedure TRVRTFReaderProperties.ReaderEndParsing(Sender: TObject);
begin
{$IFDEF RICHVIEW_DPMARGINS}
if not EditFlag then begin
if Reader.RTFState.DocProps.LeftMarginTw>0 then
RVData.GetAbsoluteRootData.GetDocProperties.Values['LeftMarginMM'] :=
IntToStr(Round(Reader.RTFState.DocProps.LeftMarginTw*127/(1440*5)));
if Reader.RTFState.DocProps.TopMarginTw>0 then
RVData.GetAbsoluteRootData.GetDocProperties.Values['TopMarginMM'] :=
IntToStr(Round(Reader.RTFState.DocProps.TopMarginTw*127/(1440*5)));
if Reader.RTFState.DocProps.RightMarginTw>0 then
RVData.GetAbsoluteRootData.GetDocProperties.Values['RightMarginMM'] :=
IntToStr(Round(Reader.RTFState.DocProps.RightMarginTw*127/(1440*5)));
if Reader.RTFState.DocProps.BottomMarginTw>0 then
RVData.GetAbsoluteRootData.GetDocProperties.Values['BottomMarginMM'] :=
IntToStr(Round(Reader.RTFState.DocProps.BottomMarginTw*127/(1440*5)));
if Reader.RTFState.DocProps.PaperWidthTw>0 then
RVData.GetAbsoluteRootData.GetDocProperties.Values['PageWidthMM'] :=
IntToStr(Round(Reader.RTFState.DocProps.PaperWidthTw*127/(1440*5)));
if Reader.RTFState.DocProps.Landscape then
RVData.GetAbsoluteRootData.GetDocProperties.Values['Landscape'] := 'Yes';
end;
{$ENDIF}
end;

---------------------------------------------------
RV_DEFS.inc
{$DEFINE RICHVIEW_DPMARGINS}
---------------------------------------------------
and add to my control
----------------------------------------------------
procedure TZRVRichEdit.SetPageProps;
begin
LeftMargin:=0;
RightMargin:=0;
If (DocProperties.Values['PageWidthMM']<>'') and (DocProperties.Values['PageWidthMM']<>'0') then
PageWidth:=MulDiv(StrToInt(DocProperties.Values['PageWidthMM']), GetDeviceCaps(Canvas.Handle, LOGPIXELSX) ,25);
If DocProperties.Values['LeftMarginMM']<>'' then
LeftMargin:=MulDiv(StrToInt(DocProperties.Values['LeftMarginMM']), GetDeviceCaps(Canvas.Handle, LOGPIXELSX) ,25);
If DocProperties.Values['RightMarginMM']<>'' then
RightMargin:=MulDiv(StrToInt(DocProperties.Values['RightMarginMM']), GetDeviceCaps(Canvas.Handle, LOGPIXELSX) ,25);
If DocProperties.Values['TopMarginMM']<>'' then
TopMargin:=MulDiv(StrToInt(DocProperties.Values['TopMarginMM']), GetDeviceCaps(Canvas.Handle, LOGPIXELSX) ,25);
If DocProperties.Values['BottomMarginMM']<>'' then
BottomMargin:=MulDiv(StrToInt(DocProperties.Values['BottomMarginMM']), GetDeviceCaps(Canvas.Handle, LOGPIXELSX) ,25);
If DocProperties.Values['Landscape'] = 'Yes' then
Orientation:=poLandscape else Orientation:=poPortrait;

if (RightMargin<>0) and (LeftMargin<>0) then begin
MaxTextWidth:=PageWidth-RightMargin-LeftMargin;
MinTextWidth:=MaxTextWidth;
end;

end;
-----------------------------------------------
call this procedure after load RTF for set properties TRV

for save properties
add Event OnSaveRTFExtra sample below
----------------------------------------
procedure TZRVRichEdit.OnSaveRTFExtra(Sender: TCustomRichView;
Area: TRVRTFSaveArea; Obj: TObject; Index1, Index2: Integer;
InStyleSheet: Boolean; var RTFCode: String);

function MMToTwips(mm: Integer): Integer;
begin
Result := Round(mm*1440*5/127);
end;

begin
if Area=rv_rtfs_Doc then
begin
RTFCode := SysUtils.Format('\paperw%d\margl%d\margt%d\margr%d\margb%d',
[MMToTwips(muldiv(MinTextWidth+LeftMargin+RightMargin,25,96)),
MMToTwips(muldiv(LeftMargin,25,96)),
MMToTwips(muldiv(TopMargin,25,96)),
MMToTwips(muldiv(RightMargin,25,96)),
MMToTwips(muldiv(BottomMargin,25,96))]);
if Orientation=poLandscape then
RTFCode :=RTFCode + '\landscape';
end;
end;
Tomas
Posts: 8
Joined: Tue Nov 22, 2005 1:57 pm

Post by Tomas »

Markus, where I can find TZRVRichEdit.SetPageProps procedure? What is class TZRVRichEdit is it?
Markus D.
Posts: 11
Joined: Mon Sep 05, 2005 7:33 am

Post by Markus D. »

It's my TForm which contains TRichViewEdit.
Add protect/public(as you wish) procedure SetPageProps and call after load RTF.
Tomas
Posts: 8
Joined: Tue Nov 22, 2005 1:57 pm

Post by Tomas »

Code code works perfect but one thing here is missing - a page Height. DO you know how to get it?
Markus D.
Posts: 11
Joined: Mon Sep 05, 2005 7:33 am

Post by Markus D. »

I don't know. RichViewEdit don't have properties like PageHeight.
Try ask Sergey (author) :)
Post Reply