📄 printersetu.pas
字号:
unit PrinterSetU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, WPRTEDefs, WPCTRMemo, WPCTRRich, StdCtrls, Printers,
WPUtil, WpPagPrp;
type
TWPPrintCheck = class(TForm)
WPRichText1: TWPRichText;
Panel1: TPanel;
Button1: TButton;
Duplex: TCheckBox;
Label1: TLabel;
FirstPageSource: TComboBox;
Label2: TLabel;
AllPageSource: TComboBox;
SetupPage: TButton;
WPPagePropDlg1: TWPPagePropDlg;
Button2: TButton;
PrintDialog1: TPrintDialog;
LandFirstpag: TCheckBox;
LandAllPag: TCheckBox;
Button3: TButton;
WPRichText2: TWPRichText;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure SetupPageClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure LandAllPagClick(Sender: TObject);
procedure WPRichText1MeasureTextPage(Sender: TObject;
PageInfo: TWPMeasurePageParam);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
procedure ReadPrinterProps;
procedure ApplyProps(wp : TWPCustomRtfEdit);
end;
var
WPPrintCheck: TWPPrintCheck;
implementation
{$R *.dfm}
procedure TWPPrintCheck.ReadPrinterProps;
begin
WPRichtext1.GetPaperBins(Printer, FirstPageSource.Items, '');
AllPageSource.Items := FirstPageSource.Items;
// WPRichtext1.GetPaperBins(Printer, AllPageSource.Items, '');
end;
procedure TWPPrintCheck.ApplyProps(wp : TWPCustomRtfEdit);
begin
if Duplex.Checked then
wp.PrintParameter.DuplexMode := wpdVertical
else wp.PrintParameter.DuplexMode := wpdNone;
if FirstPageSource.ItemIndex>=0 then
wp.PrintParameter.FirstPagePaperSource :=
Integer(FirstPageSource.Items.Objects[FirstPageSource.ItemIndex])
else wp.PrintParameter.FirstPagePaperSource := 0;
if AllPageSource.ItemIndex>=0 then
wp.PrintParameter.AllPagePaperSource :=
Integer(AllPageSource.Items.Objects[AllPageSource.ItemIndex])
else wp.PrintParameter.AllPagePaperSource := 0;
end;
procedure TWPPrintCheck.Button1Click(Sender: TObject);
begin
ApplyProps(WPRichText1);
WPRichtext1.PrintParameter.PrintOptions :=
WPRichtext1.PrintParameter.PrintOptions + [wpUsePrintPageNumber];
WPRichText1.Print;
end;
procedure TWPPrintCheck.FormCreate(Sender: TObject);
begin
ReadPrinterProps;
WPRichText1.PaperDefs.Init(true); // Needed for page setup dialog!
WPRichText1.ReadPrinterProperties;
WPRichText2.ReadPrinterProperties;
end;
procedure TWPPrintCheck.SetupPageClick(Sender: TObject);
begin
if WPPagePropDlg1.Execute then
WPRichText2.Header.Assign(WPRichText1.Header);
end;
procedure TWPPrintCheck.Button2Click(Sender: TObject);
begin
PrintDialog1.Execute;
end;
procedure TWPPrintCheck.LandAllPagClick(Sender: TObject);
begin
WPRichtext1.DelayedReformat;
end;
procedure TWPPrintCheck.WPRichText1MeasureTextPage(Sender: TObject;
PageInfo: TWPMeasurePageParam);
var check : TCheckBox;
begin
if PageInfo.pagenr=1 then
check := LandFirstpag
else check := LandAllPag;
if check.State=cbChecked then
begin
PageInfo.widthtw := WPRichtext1.Header._Layout.paperh;
PageInfo.heighttw := WPRichtext1.Header._Layout.paperw;
PageInfo.changed := TRUE;
end else
if check.State=cbUnChecked then
begin
PageInfo.widthtw := WPRichtext1.Header._Layout.paperw;
PageInfo.heighttw := WPRichtext1.Header._Layout.paperh;
PageInfo.changed := TRUE;
end else
if check.State=cbGrayed then
begin
PageInfo.widthtw := WPRichtext1.Header.PageWidth;
PageInfo.heighttw := WPRichtext1.Header.PageHeight;
PageInfo.changed := TRUE;
end;
end;
procedure TWPPrintCheck.Button3Click(Sender: TObject);
begin
ApplyProps(WPRichText1);
ApplyProps(WPRichText2);
// We need global page numbering
WPRichtext1.PrintParameter.PrintOptions :=
WPRichtext1.PrintParameter.PrintOptions + [wpUsePrintPageNumber];
// It is not visible - so format it!
WPRichtext2.ReformatAll;
// and get the total page count
WPRichtext1.Enviroment.CombinedPrintPageCount :=
WPRichtext1.PageCount +
WPRichtext2.PageCount;
// Now start the printing
WPRichtext1.BeginPrint('');
try
WPRichtext1.Print;
WPRichtext2.Print;
finally
WPRichtext1.EndPrint;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -