Page 1 of 1
RTF page orientation and PageSize
Posted: Thu Jan 12, 2006 11:25 am
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
Posted: Thu Jan 12, 2006 7:23 pm
by Sergey Tkachenko
In the current version, reading these RTF properties is not possible (without modification of source code)
Posted: Thu Jan 12, 2006 10:25 pm
by Tomas
So I need to read these constant by myself before loading RTF to TRV. Maybe you have demo how to do it?
Posted: Fri Jan 13, 2006 3:52 am
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;
Posted: Sat Jan 14, 2006 6:07 pm
by Tomas
Markus, where I can find TZRVRichEdit.SetPageProps procedure? What is class TZRVRichEdit is it?
Posted: Sat Jan 14, 2006 6:44 pm
by Markus D.
It's my TForm which contains TRichViewEdit.
Add protect/public(as you wish) procedure SetPageProps and call after load RTF.
Posted: Mon Jan 16, 2006 10:37 am
by Tomas
Code code works perfect but one thing here is missing - a page Height. DO you know how to get it?
Posted: Mon Jan 16, 2006 12:03 pm
by Markus D.
I don't know. RichViewEdit don't have properties like PageHeight.
Try ask Sergey (author)