trichview.com

trichview.support




Re: Help With RVPrint/PageSetup


Return to index


Author

Message

Sergey Tkachenko

Posted: 06/09/2005 10:07:32


1) Margins are stored in RVPrint

2) Properties of header and footer are stored in global objects

RVA_HeaderInfo and RVA_FooterInfo (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


uses Printers;


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;

  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(PaperNames);

      FreeMem(PaperCodes);

    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;


3.b) Paper size


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;


You can find a list of available paper sizes in Windows API Help (Delphi

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:


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;


You can see how to get a list of available paper sizes and their names in

the RichViewActions source code (in page setup form)


RichViewActions header and footers must be printed only when printing using

printing actions.


> Hi,

>

> Is there anyway of getting at the settings on the Page Setup Form? I know

> that margins are stored in the RVPrint component, but is there anyway to

> read/set (for example) the page orientation, the headers and footers etc.

>

> In addition, when I set footers and headers, they do not print with my

> document? What am I doing wrong?

>

> Thanks,

>

> Paul Jones

> Jalco Software Ltd,

> www.jalco.co.uk

> www.aladesc.co.uk

>

>





Powered by ABC Amber Outlook Express Converter