Como imprimir um arquivo pelo Delphi?
Está função recupera o nome da impressora padrão.
É necessário estar declarado Printers e ShellApi na seção uses,
em versões unicode declare Vcl.Printers e WinApi.ShellApi.
Segue o código fonte da função:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| 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 impresora, 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 impresora, 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:\Exemplos\ShowDelphi.txt');
end; |
procedure TForm1.Button1Click(Sender: TObject);
begin
PrintFile('C:\Exemplos\ShowDelphi.txt');
end;
-
InfusTec
-
6.711 views
- 0 comentários
- 27 de abril de 2015
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo