Page format

General TRichView support forum. Please post your questions here
Post Reply
coolbeab
Posts: 6
Joined: Sun Jul 24, 2016 10:20 pm

Page format

Post by coolbeab »

Hi;
I want to know how to change page size to A5 format at run time
thank you.
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you use TRichView or ScaleRichView?
coolbeab
Posts: 6
Joined: Sun Jul 24, 2016 10:20 pm

Post by coolbeab »

HI
i use TRichView
Sergey Tkachenko
Site Admin
Posts: 17534
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

While ScaleRichView can automatically set paper size when printing, TRichView uses the paper format specified for the printer.

So, if you want to print on A5 paper, you need to set this format to the printer before printing.

This code shows how to do it:

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;
Call

Code: Select all

SetPaperSize(DMPAPER_A5)
After that, you can print using TRVPrint component: call AssignSource, FormatPages, Print methods.
coolbeab
Posts: 6
Joined: Sun Jul 24, 2016 10:20 pm

Post by coolbeab »

thank you very much you are really a genius.
Post Reply