



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; |
Exemplo de uso:
1 2 3 4 | procedure TForm1.Button1Click(Sender: TObject); begin PrintFile('C:\teste.txt'); end; |