Page 1 of 1

Page format

Posted: Sun Jul 24, 2016 10:27 pm
by coolbeab
Hi;
I want to know how to change page size to A5 format at run time
thank you.

Posted: Mon Jul 25, 2016 6:18 am
by Sergey Tkachenko
Do you use TRichView or ScaleRichView?

Posted: Mon Jul 25, 2016 11:52 am
by coolbeab
HI
i use TRichView

Posted: Mon Jul 25, 2016 12:01 pm
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.

Posted: Mon Jul 25, 2016 10:27 pm
by coolbeab
thank you very much you are really a genius.