Como imprimir um arquivo na impressora padrão?
Veja uma dica simples para a impressão de arquivos na impressora padrão.
Declare Printers, SysUtils e ShellAPI,
versões unicode declare Vcl.Printers, System.SysUtils e Winapi.ShellAPI.
Segue o código fonte:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| procedure PrintFile(aFile : TFileName);
var
Device: array[0..255] of Char;
Driver: array[0..255] of Char;
Port: array[0..255] of Char;
S: string;
hDeviceMode: THandle;
begin
// Selecione uma impressora, neste caso é a padrão.
Printer.PrinterIndex := -1;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
ShellExecute(Application.Handle, 'printto', PChar(aFile), PChar(S), nil, SW_HIDE);
end; |
procedure PrintFile(aFile : TFileName);
var
Device: array[0..255] of Char;
Driver: array[0..255] of Char;
Port: array[0..255] of Char;
S: string;
hDeviceMode: THandle;
begin
// Selecione uma impressora, neste caso é a padrão.
Printer.PrinterIndex := -1;
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
ShellExecute(Application.Handle, 'printto', PChar(aFile), PChar(S), nil, SW_HIDE);
end;
Exemplo de uso:
1
2
3
4
| procedure TForm1.Button1Click(Sender: TObject);
begin
PrintFile('C:\teste.txt');
end; |
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintFile('C:\teste.txt');
end;
-
InfusTec
-
8.073 views
- 0 comentários
- 16 de abril de 2015
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo