-
Notifications
You must be signed in to change notification settings - Fork 1
/
VirtualPrinter.pas
executable file
·112 lines (98 loc) · 2.45 KB
/
VirtualPrinter.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
unit VirtualPrinter;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Printers;
type
TVirtualPrinterForm = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
buffer : String;
public
{ Public declarations }
procedure Flush;
procedure AddByteToBuffer(data: Char);
function GetBuffer: String;
procedure SetBuffer(data: String);
end;
var
VirtualPrinterForm: TVirtualPrinterForm;
implementation
{$R *.dfm}
procedure TVirtualPrinterForm.AddByteToBuffer(data : Char);
begin
buffer := buffer + data;
end;
function TVirtualPrinterForm.GetBuffer : String;
begin
result := buffer;
end;
procedure TVirtualPrinterForm.SetBuffer(data : String);
begin
buffer := data;
end;
procedure TVirtualPrinterForm.Flush;
var
i : Integer;
line : String;
begin
for i := 1 to Length(buffer) do
begin
if (buffer[i] = #13) then
begin
Memo1.Lines.Add(line);
line := '';
end
else
if (buffer[i] <> #10) then
line := line + buffer[i];
end;
if line <> '' then
Memo1.Lines.Add(line);
Show;
buffer := '';
end;
procedure TVirtualPrinterForm.Button2Click(Sender: TObject);
begin
Memo1.Lines.Clear;
end;
procedure TVirtualPrinterForm.Button1Click(Sender: TObject);
var
printDialog : TPrintDialog;
myPrinter : TPrinter;
myFile : TextFile;
i : Integer;
Line : Integer;
begin
// Create a printer selection dialog
printDialog := TPrintDialog.Create(VirtualPrinterForm);
// If the user has selected a printer (or default), then print!
if printDialog.Execute then
begin
// Use the Printer function to get access to the
// global TPrinter object.
// All references below are to the TPrinter object
myPrinter := Printer;
with myPrinter do
begin
Line := 0;
Printer.BeginDoc;
for i := 0 to Memo1.Lines.Count - 1 do
Printer.Canvas.Font.Size := 10;
Printer.Canvas.Font.Name := 'Courier New';
begin
Printer.Canvas.TextOut(0, Line, Memo1.Lines[i]);
Line := Line + Abs(Printer.Canvas.Font.Height);
if (Line >= Printer.pageHeight) then
Printer.newPage
end;
Printer.EndDoc;
end;
end;
end;
end.