2) Properties of header and footer are stored in global objects
RVAControlPanel.Header and RVAControlPanel.Footer (Text, Alignment, PrintOnFirstPage
properties)
3) Page size, orientation and source are stored in the global for the
application printer settings. They are accessible via global Printer object
(units Printers). Only orientation can be changed easily -
Printer.Orientation.
Other properties can be changed using WinAPI functions:
3.a) Changing paper source
Code: Select all
// make sure that WinSpool is defined after Windows in uses
uses Printers, WinSpool;
type
TBinName = array [0..23] of Char;
TBinNames = array [0..1000] of TBinName;
PBinNames = ^TBinNames;
TWordArray = array [0..1000] of Word;
PWordArray = ^TWordArray;
procedure GetAvailablePaperSources;
var ADevice, ADriver, APort: array[0..79] of Char;
ADeviceMode: THandle;
DevMode: PDeviceMode;
BinCount: Integer;
BinNames: PBinNames;
BinCodes: PWordArray;
begin
Printer.GetPrinter(ADevice,ADriver,APort,ADeviceMode);
if ADeviceMode<>0 then begin
DevMode := PDeviceMode(GlobalLock(ADeviceMode))
end
else
raise Exception.Create('Error initializing printer');
BinCount := DeviceCapabilities(ADevice, APort, DC_BINNAMES, nil, DevMode);
GetMem(BinNames, sizeof(TBinName)*BinCount);
GetMem(BinCodes, sizeof(Integer)*BinCount);
try
DeviceCapabilities(ADevice, APort, DC_BINNAMES, Pointer(BinNames), DevMode);
DeviceCapabilities(ADevice, APort, DC_BINS, Pointer(BinCodes), DevMode);
{
At this point, BinNames[0..BinCount-1] contain names of paper sources,
BinCodes[0..BinCount-1] contain their codes that can be used in SetPaperSource.
Store them somewhere.
}
finally
FreeMem(BinNames);
FreeMem(BinCodes);
end;
GlobalUnlock(ADeviceMode);
end;
procedure SetPaperSource(PaperSource: 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_DEFAULTSOURCE;
DevMode.dmDefaultSource := PaperSource;
GlobalUnlock(ADeviceMode);
Printer.SetPrinter(ADevice,ADriver,APort,ADeviceMode);
end;
Code: Select all
uses Printers;
procedure SetPaperSize(PaperSize: 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 := PaperSize;
GlobalUnlock(ADeviceMode);
Printer.SetPrinter(ADevice,ADriver,APort,ADeviceMode);
end;
menu: Help | Windows SDK).
Search DEVMODE in the help index, then search for DMPAPER_*** constants.
For example, SetPaperSize(DMPAPER_A4)
Do not forget to call RVPrint.FormatPages after any change in paper sizes.
You can get the current printer's paper size:
Code: Select all
function GetPaperSize: 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');
Result := DevMode.dmPaperSize;
end;
the RichViewActions source code (in page setup form)
Note: in new version of Delphi, use String instead of array[0..79] of Char.