zhijun_chen
asked on
How can I set a printer's papersize?
Hello,
My program use many report,and it's papersize isn't same,How can I let the user Preview the report use the correspond papersize,for example:
Set the Printer's papersize to A3;
Report_PaperSize_A3.Previe w;
Set the Printer's PaperSize to A4;
Report_PaperSize_A4.Previe w;
How can I relize it?
thank u.
zhijun_chen
My program use many report,and it's papersize isn't same,How can I let the user Preview the report use the correspond papersize,for example:
Set the Printer's papersize to A3;
Report_PaperSize_A3.Previe
Set the Printer's PaperSize to A4;
Report_PaperSize_A4.Previe
How can I relize it?
thank u.
zhijun_chen
you can change teh paper size and bin of printer like so:
unit Unit1;
interface
uses
Windows, Messages,Printers, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender : TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
pDMode^.dmPaperSize := DMPAPER_LEGAL;
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := 100 {SomeValueInTenthsOfAMilli meter};
pDMode^.dmPaperLength := 100 {SomeValueInTenthsOfAMilli meter};
{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex; Printer.BeginDoc;
Printer.Canvas.Font.Name := 'Courier New';
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Color: =ClRed;
Printer.Canvas.TextOut(100 ,100, 'Test 1');
Printer.EndDoc;
end;
end.
Regards Barry
unit Unit1;
interface
uses
Windows, Messages,Printers, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin
Printer.GetPrinter(Device,
if hDMode <> 0 then begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then begin
{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
pDMode^.dmPaperSize := DMPAPER_LEGAL;
{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := 100 {SomeValueInTenthsOfAMilli
pDMode^.dmPaperLength := 100 {SomeValueInTenthsOfAMilli
{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;
GlobalUnlock(hDMode);
end;
end;
Printer.PrinterIndex := Printer.PrinterIndex; Printer.BeginDoc;
Printer.Canvas.Font.Name := 'Courier New';
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Color:
Printer.Canvas.TextOut(100
Printer.EndDoc;
end;
end.
Regards Barry
ASKER
Thank u,all
I want it work with QuickRep, How can do it?
To Inthe:
u perhas miss a word:
Printer.SetPrinter(.....), it doesn't work.
zhijun_chen
I want it work with QuickRep, How can do it?
To Inthe:
u perhas miss a word:
Printer.SetPrinter(.....),
zhijun_chen
You will need to include printers in your uses clause.
Did you try my suggestion? This allows you to preview the report with any required paper size or the existing default paper size in the printer.
Cheers,
Raymond.
Did you try my suggestion? This allows you to preview the report with any required paper size or the existing default paper size in the printer.
Cheers,
Raymond.
You can set the papersize after you dropped a QuickReport on the form by right-clicking on it and selecting 'Report Settings'
ASKER
Thank u,rwilson
I have try your suggestion,But it doesn't work, the Quickreport's preview
window still is the default settings,for example, if I set the printer's papersize A4 as My printer's default(In windows), the Quickreport's preview window still be A4.
To Epsylon,
I want to create the report at runtime.
thank u,anyway.
zhijun_chen
I have try your suggestion,But it doesn't work, the Quickreport's preview
window still is the default settings,for example, if I set the printer's papersize A4 as My printer's default(In windows), the Quickreport's preview window still be A4.
To Epsylon,
I want to create the report at runtime.
thank u,anyway.
zhijun_chen
did you try changing the printers papersize by code first then calling preview?
ASKER
Hello inthe,
I have try, but it doesn't work.
I think the only solution is to change the windows's default printer settings at runtime, but how can do it?
thank u.
I have try, but it doesn't work.
I think the only solution is to change the windows's default printer settings at runtime, but how can do it?
thank u.
maybe you can use the quickreports settings sometyhing like:
//add to uses QRPRNTR,printers;
{the orientation needs printers unit}
var
a: TPrinterSettings;
begin
a.PaperSize := A3;
a.Copies := 1;
a.Orientation := PoPortrait;
a.ApplySettings;
then call preview..
//add to uses QRPRNTR,printers;
{the orientation needs printers unit}
var
a: TPrinterSettings;
begin
a.PaperSize := A3;
a.Copies := 1;
a.Orientation := PoPortrait;
a.ApplySettings;
then call preview..
did you try?
This is based on I found in my PAQ collection, it may be of use:
What you need to do is to add a public property of your preview form of type TQuickRep like the following:
type
TfrmPreview = class(TForm)
QRPreview: TQRPreview;
.....
public
{ Public declarations }
CurrentReport : TQuickRep;
end;
In the OnPreview event of the report, you would use something like:
procedure TfrmMyReport.QuickRep1Prev iew(Sender : TObject);
begin
with frmPreview do
begin
CurrentReport := QuickRep1;
QRPreview.QRPrinter := TQRPrinter(Sender);
Show;
end
end;
That lets you reference the calling report through the preview's CurrentReport variable. Then to change the papersize you would do something like the following:
with CurrentReport.PrinterSetti ngs do
begin
{ Set the paper size }
PaperSize := A3;
ApplySettings; // Needed?
end;
QRPreview.qrprinter.Print;
Cheers,
Raymond.
What you need to do is to add a public property of your preview form of type TQuickRep like the following:
type
TfrmPreview = class(TForm)
QRPreview: TQRPreview;
.....
public
{ Public declarations }
CurrentReport : TQuickRep;
end;
In the OnPreview event of the report, you would use something like:
procedure TfrmMyReport.QuickRep1Prev
begin
with frmPreview do
begin
CurrentReport := QuickRep1;
QRPreview.QRPrinter := TQRPrinter(Sender);
Show;
end
end;
That lets you reference the calling report through the preview's CurrentReport variable. Then to change the papersize you would do something like the following:
with CurrentReport.PrinterSetti
begin
{ Set the paper size }
PaperSize := A3;
ApplySettings; // Needed?
end;
QRPreview.qrprinter.Print;
Cheers,
Raymond.
with regards to:
I think the only solution is to change the windows's default printer settings at runtime, but how can do it?
maybe use the PrintSetupDialog component
(i cant remember if it is standard component or i downloaded it)
I think the only solution is to change the windows's default printer settings at runtime, but how can do it?
maybe use the PrintSetupDialog component
(i cant remember if it is standard component or i downloaded it)
TPrinterSetupDialog is a standard component
Raymond.
Raymond.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mscatena ,
please leave comments only,do you not see i already posted that before ?
please leave comments only,do you not see i already posted that before ?
eg:
QuickRep1.PaperSize := A4;
Set is to default to use the paper size currently loaded into the printer.
Cheers,
Raymond.