Hi
I am saving the rvf to a database but the page setup is lost. It there a work around to save and retore the page setup information.
Thanks Mike
version 1.9 saving page setup
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
It's by design. TRichView was designed to print using the current application printing settings. These settings are saved in ScaleRichView (that was designed as a WYSIWYG text processor), not in TRichView.
Nevertheless, with some additional code, you can save and load page setup in RVF document.
In TRichView version 10.0+, there is a property DocParameters, containing subproperties for storing page size, orientation and margins.
This property is saved and loaded in RVF if rvfoSaveDocProperties and rvfoLoadDocProperties are included in RVFOptions property.
How to assign DocParameters:
If you use RichViewActions, you may wish to store additional properties, for example properties of header and footer. See http://www.trichview.com/forums/viewtopic.php?t=10 how to access them.
You can use rve.DocProperties to store them:
After loading RVF, you need to activate the read page settings.
How to activate DocParameters:
Nevertheless, with some additional code, you can save and load page setup in RVF document.
In TRichView version 10.0+, there is a property DocParameters, containing subproperties for storing page size, orientation and margins.
This property is saved and loaded in RVF if rvfoSaveDocProperties and rvfoLoadDocProperties are included in RVFOptions property.
How to assign DocParameters:
Code: Select all
procedure GetPaperWH(var Width, Height: Extended);
var DC: HDC;
begin
DC := Printer.Handle;
Width := GetDeviceCaps(DC, PHYSICALWIDTH) / GetDeviceCaps(DC, LOGPIXELSX);
Height := GetDeviceCaps(DC, PHYSICALHEIGHT) / GetDeviceCaps(DC, LOGPIXELSY);
end;
var
InchPerMM: Extended;
W,H: Extended;
begin
...
rve.DocParameters.Units := rvuInches;
InchPerMM := 1/rve.DocParameters.UnitsPerInch(rvuMillimeters);
rve.DocParameters.LeftMargin := RVPrint1.LeftMarginMM*InchPerMM;
rve.DocParameters.TopMargin := RVPrint1.TopMarginMM*InchPerMM;
rve.DocParameters.RightMargin := RVPrint1.RightMarginMM*InchPerMM;
rve.DocParameters.BottomMargin := RVPrint1.BottomMarginMM*InchPerMM;
rve.DocParameters.HeaderY := RVPrint1.HeaderYMM*InchPerMM;
rve.DocParameters.FooterY := RVPrint1.FooterYMM*InchPerMM;
rve.DocParameters.MirrorMargins := RVPrint1.MirrorMargins;
rve.DocParameters.Orientation := Printer.Orientation;
GetPaperWH(W,H);
rve.DocParameters.PageWidth := W;
rve.DocParameters.PageHeight := H;
end;
You can use rve.DocProperties to store them:
Code: Select all
rve.DocProperties.Clear;
rve.DocProperties.Add('HeaderText='+RVA_HeaderInfo.Text);
...
How to activate DocParameters:
Code: Select all
function ConvertPageSizeToPageFormat(PaperWidth, PaperHeight: Integer): Integer;
var tmp: Integer;
begin
if PaperHeight<PaperWidth then begin
tmp := PaperHeight;
PaperHeight := PaperWidth;
PaperWidth := tmp;
end;
// this is not a complete list (and mistakes are possible)
if (PaperWidth = 297) and (PaperHeight = 420) then
Result := DMPAPER_A3
else if (PaperWidth = 210) and (PaperHeight = 297) then
Result := DMPAPER_A4
else if (PaperWidth = 148) and (PaperHeight = 210) then
Result := DMPAPER_A5
else if (PaperWidth = 257) and (PaperHeight = 364) then
Result := DMPAPER_B4 // JIS
else if (PaperWidth = 182) and (PaperHeight = 257) then
Result := DMPAPER_B5 // JIS
else if (PaperWidth = 216) and (PaperHeight = 279) then
Result := DMPAPER_LETTER
else if (PaperWidth = 216) and (PaperHeight = 356) then
Result := DMPAPER_LEGAL
else if (PaperWidth = 215) and (PaperHeight = 355) then
Result := DMPAPER_LEGAL
else if (PaperWidth = 279) and (PaperHeight = 432) then
Result := DMPAPER_TABLOID
else if (PaperWidth = 279) and (PaperHeight = 432) then
Result := DMPAPER_LEDGER
else if (PaperWidth = 140) and (PaperHeight = 216) then
Result := DMPAPER_STATEMENT
else if (PaperWidth = 203) and (PaperHeight = 254) then
Result := DMPAPER_QUARTO
else if (PaperWidth = 203) and (PaperHeight = 330) then
Result := DMPAPER_FOLIO
else if (PaperWidth = 184) and (PaperHeight = 267) then
Result := DMPAPER_EXECUTIVE
else if (PaperWidth = 99) and (PaperHeight = 225) then
Result := DMPAPER_ENV_9
else if (PaperWidth = 105) and (PaperHeight = 241) then
Result := DMPAPER_ENV_10
else if (PaperWidth = 114) and (PaperHeight = 264) then
Result := DMPAPER_ENV_11
else if (PaperWidth = 121) and (PaperHeight = 279) then
Result := DMPAPER_ENV_12
else if (PaperWidth = 127) and (PaperHeight = 292) then
Result := DMPAPER_ENV_14
else
Result := 0;
end;
procedure SetPaperWH(Width, Height: Integer);
var ADevice, ADriver, APort: array[0..79] of Char;
ADeviceMode: THandle;
DevMode: PDeviceMode;
begin
Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode);
if ADeviceMode<>0 then begin
DevMode := PDeviceMode(GlobalLock(ADeviceMode))
end
else
raise Exception.Create('Error initializing printer');
DevMode.dmFields := DevMode.dmFields or DM_PAPERSIZE;
DevMode.dmPaperSize := ConvertPageSizeToPageFormat(Width, Height);
if DevMode.dmPaperSize=0 then begin
// the results are correct even if standard PaperSize is not detected
DevMode.dmPaperWidth := Width*10;
DevMode.dmPaperLength := Height*10;
end;
GlobalUnlock(ADeviceMode);
Printer.SetPrinter(ADevice,ADriver,APort,ADeviceMode);
end;
var MMPerUnit: Extended;
begin
...
// assigning margins, HeaderYMM, FooterYMM, MirrorMargins
RVPrint1.AssignDocParameters(rve.DocParameters);
Printer.Orientation := rve.DocParameters.Orientation;
MMPerUnit := rve.DocParameters.UnitsPerInch(rvuMillimeters)/
rve.DocParameters.UnitsPerInch(rve.DocParameters.Units);
SetPaperWH(Round(rve.DocParameters.PageWidth*MMPerUnit),
Round(rve.DocParameters.PageHeight*MMPerUnit));
end;
Last edited by Sergey Tkachenko on Tue May 12, 2009 11:24 am, edited 2 times in total.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Hi
How do I get the information in bold as I do not have DocParameters
Mike
procedure GetPaperWH(var Width, Height: Extended);
var DC: HDC;
begin
DC := Printer.Handle;
Width := GetDeviceCaps(DC, PHYSICALWIDTH) / GetDeviceCaps(DC, LOGPIXELSX);
Height := GetDeviceCaps(DC, PHYSICALHEIGHT) / GetDeviceCaps(DC, LOGPIXELSY);
end;
var
InchPerMM: Extended;
W,H: Extended;
begin
...
rve.DocParameters.Units := rvuInches;
InchPerMM := 1/rve.DocParameters.UnitsPerInch(rvuMillimeters);
rve.DocParameters.LeftMargin := RVPrint1.LeftMarginMM*InchPerMM;
rve.DocParameters.TopMargin := RVPrint1.TopMarginMM*InchPerMM;
rve.DocParameters.RightMargin := RVPrint1.RightMarginMM*InchPerMM;
rve.DocParameters.BottomMargin := RVPrint1.BottomMarginMM*InchPerMM;
rve.DocParameters.HeaderY := RVPrint1.HeaderYMM*InchPerMM;
rve.DocParameters.FooterY := RVPrint1.FooterYMM*InchPerMM;
rve.DocParameters.MirrorMargins := RVPrint1.MirrorMargins;
rve.DocParameters.Orientation := Printer.Orientation;
GetPaperWH(W,H);
rve.DocParameters.PageWidth := W;
rve.DocParameters.PageHeight := H;
end;
How do I get the information in bold as I do not have DocParameters
Mike
procedure GetPaperWH(var Width, Height: Extended);
var DC: HDC;
begin
DC := Printer.Handle;
Width := GetDeviceCaps(DC, PHYSICALWIDTH) / GetDeviceCaps(DC, LOGPIXELSX);
Height := GetDeviceCaps(DC, PHYSICALHEIGHT) / GetDeviceCaps(DC, LOGPIXELSY);
end;
var
InchPerMM: Extended;
W,H: Extended;
begin
...
rve.DocParameters.Units := rvuInches;
InchPerMM := 1/rve.DocParameters.UnitsPerInch(rvuMillimeters);
rve.DocParameters.LeftMargin := RVPrint1.LeftMarginMM*InchPerMM;
rve.DocParameters.TopMargin := RVPrint1.TopMarginMM*InchPerMM;
rve.DocParameters.RightMargin := RVPrint1.RightMarginMM*InchPerMM;
rve.DocParameters.BottomMargin := RVPrint1.BottomMarginMM*InchPerMM;
rve.DocParameters.HeaderY := RVPrint1.HeaderYMM*InchPerMM;
rve.DocParameters.FooterY := RVPrint1.FooterYMM*InchPerMM;
rve.DocParameters.MirrorMargins := RVPrint1.MirrorMargins;
rve.DocParameters.Orientation := Printer.Orientation;
GetPaperWH(W,H);
rve.DocParameters.PageWidth := W;
rve.DocParameters.PageHeight := H;
end;
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
You can store all values in DocProperties. It's simpler to store all values in mm.
Saving
Reading:
Saving
Code: Select all
rve.DocPproperties.Add('LeftMargin='+IntToStr(RVPrint1.LeftMarginMM));
...
GetPaperWH(W,H);
rve.DocProperties.Add('PageWidth='+IntToStr(Round(W*25.4));
rve.DocProperties.Add('PageHeight='+IntToStr(Round(H*25.4));
Code: Select all
RVPrint1.LeftMarginMM := StrToIntDef(rve.DocProperties.Values['LeftMargin'], 20);
...
SetPaperWH(
StrToIntDef(rve.DocProperties.Values['PageWidth'], 210),
StrToIntDef(rve.DocProperties.Values['PageHeight'], 297));