Hello,
Does anyone know to read RTF page orientation(Portrait, Landscape) and Page Size(A4, A3, Letter) which is loaded in TRichView?
Regards,
Tomas
RTF page orientation and PageSize
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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;
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;