|
Print
Properties (Updated 05/06)

This property makes it possible to set
PrintOoptions like header, footer, margins, paper orientation
programmatically.
At design-time, the properties are loaded
from registry and margins converted to the unit of
measurement found in your LocaleID.
This means that the
properties will appear as in the PageSetup print dialog.
At run-time, Embeddedwb checks the users
LocaleID and makes the nessecary conversions between inch/millimeters
and find the proper DecimalSeparator before it sends
strings to the PageSetup-dialog. This is important in
international applications.
If you call function "Print"
with PrintOptions.enabled := true; then a few thing will happnend as folowing:
1. The PageSetup dialog will
be opened outside the application screen.
2. The PrintOptions-values are
entered in the dialog before it opens.
3. Then, the dialog is closed and then
"normal" Print-function will be called.
IIf you do not want to use PrintOptions, set PrintOptions.Enabled := False;
Notes:
1. You mast have the EmbeddedWB fully load a document before sending the document to print1
2. You can easily add more properties. Just
keep in mind that the Printsetup dialog has changed in
Windows 2000.
3. You should avoid using Windows-titles as identifiers
for dialog-boxes if you develop multi-language
applications.
Download a Printing EmbeddedWB demo
|
Code samples:
// In this example we send a document to print in landscape orientation with a header.
procedure TMainFrm.LanscapeDlgClick(Sender: TObject);
begin
with EmbeddedWB1.PrintOptions do
begin
Orientation:=poLandscape;
Margins.Left:=16.75; // always use the unit of measurement defined on your own computer.
Header:='This is my new header';
end;
EmbeddedWB1.PrintWithOptions;
end;
// In this example we send a document to print in portrait orientation with a header.
procedure TMainFrm.LanscapeDlgClick(Sender: TObject);
begin
with EmbeddedWB1.PrintOptions do
begin
Orientation:=poPortrait;
Margins.Left:=16.75; // always use the unit of measurement defined on your own computer.
Header:='This is my new header';
end;
EmbeddedWB1.PrintWithOptions;
end;
|
Set Print-Options programmatically. (Version 1)
The following
sample shows an easy way to programmatically set options for print (number of
copies, paper orientation, header, footer, margins etc.).
The application opens the
PageSetup and Print dialogs, makes the modifications and close them again before
they become visible.
You can use the functions EnumChildWindows and
GetCtrlId to get the ControlID for other options you want to set
programmatically.
|
//Add to the private
section in your main form:
private
{ Private declarations }
procedure WMActivate(var Msg: TWMActivate); message WM_ACTIVATE;
type
TPrintOptions = record
Copies: Integer; //Number of copies
Portrait: Boolean; //Paper orientation
Left: string; //Left Margin
Top: string; //Top Margin
Right: string; //Right Margin
Bottom: string; //Bottom Margin
Header: string; //Header string
Footer: string; //Footer string
end;
var
PrintOptions: TPrintOptions;
bPrintWithOpt: Boolean;
// Add to implementation part: procedure TMainFrm.WMActivate(var Msg: TWMActivate);
var
S: string;
h, wnd: HWND;
Item, I: Integer;
begin
if bPrintWithOpt and (msg.active = 0) then
begin
bPrintWithOpt := false;
wnd := Msg.ActiveWindow;
I := GetWindowTextLength(wnd);
SetLength(S, I + 1);
GetWindowText(Wnd, PChar(S), I + 1);
if S = 'Print'#0 then
begin
SetDlgItemInt(wnd, 1154, PrintOptions.Copies, FALSE);
SendDlgItemMessage(Wnd, 1, BM_CLICK, 0, 0);
bPrintWithOpt := true;
end
else
if S = 'Page Setup'#0 then
begin
if PrintOptions.Portrait then
SendDlgItemMessage(Wnd, 1056, BM_CLICK, 0, 0)
else
SendDlgItemMessage(Wnd, 1057, BM_CLICK, 0, 0);
SetDlgItemText(wnd, 8147, PChar(PrintOptions.Header));
SetDlgItemText(wnd, 8149, PChar(PrintOptions.Footer));
SetDlgItemText(wnd, 1155, PChar(PrintOptions.Left));
SetDlgItemText(wnd, 1156, PChar(PrintOptions.Top));
SetDlgItemText(wnd, 1157, PChar(PrintOptions.Right));
SetDlgItemText(wnd, 1158, PChar(PrintOptions.Bottom));
SendDlgItemMessage(Wnd, 1, BM_CLICK, 0, 0);
bPrintWithOpt := true;
end;
end;
end;
// Here are 2 examples to add as click events into the implementation part:
// Example1: Lanscape printing without a dialog, with 2 copies a footer and a header. procedure TMainFrm.LandscapeNoDlgClick(Sender: TObject);
begin
if Assigned(EmbeddedWB1.Document) then
begin
with PrintOptions do
begin
Copies := 1;
Portrait := False;
Footer := 'This is my Footer';
Header := 'This is my Header';
Left := '25,0';
Top := '20,0';
Right := '22,0';
Bottom := '19,7';
end;
bPrintWithOpt := True;
Embeddedwb1.pagesetup(true);
EmbeddedWB1.Print;
bPrintWithOpt := False;
end
else showmessage('Please assign a document before using this feature!');
end;
//Example 2: Portrait printing without a dialog, with 2 copies a footer and a header.
procedure TMainFrm.PortraiteNoDlgClick(Sender: TObject);
begin
if Assigned(EmbeddedWB1.Document) then
begin
with PrintOptions do
begin
Copies := 2;
Portrait := True;
Footer := 'This is my Footer';
Header := 'This is my Header';
Left := '25,0';
Top := '20,0';
Right := '22,0';
Bottom := '19,7';
end;
bPrintWithOpt := True;
Embeddedwb1.pagesetup(true);
EmbeddedWB1.Print;
bPrintWithOpt := False;
end
else showmessage('Please assign a document before using this feature!');
end;
|
More Info from Microsoft: HOWTO:
Print Custom Headers and Footers for a WebBrowser Control
|