GARANTIR DESCONTO

Fórum Como Montar o cupom não fiscal e Imprimir na impressora não fiscal #466072

06/01/2014

0

Olá a todos !

Estou desenvolvendo um sistema de restaurante simples, só que a cliente quer imprimir o relatório de venda na impressora não fiscal (não sei ainda qual modelo e marca comprar).
eu nunca desenvolvi algo parecido alguém pode me ajudar, me falando como faço o layout do cupom e como mando a impressão para a impressora não fiscal.

conto com a colaboração de todos.
Josenildo Rosa

Josenildo Rosa

Responder

Post mais votado

17/07/2015

ta ai como fazer pra imprimir em qualquer impressora existente no mercado tanto usb como serial ou paralela vc precisa da unita CharPrinter pode conseguir na internet ou me passe seu email que te envio vou postar ela inteira aqui

procedure TFmImpressao.btnbalcaoClick(Sender: TObject);
var prn:TAdvancedPrinter;
ln, linha1, linha2, linha3, linha4, linha5, linha6, linha7, linha8, linha9, linha10, tamanho: string;
tmdesc:integer;
qtdelinha: currency;
begin
ln := #13 + #10;
SetDefaultPrinter(simpbalcao);
prn := TAdvancedPrinter.Create;
Prn.OpenDoc('CUPOM DE VENDA');
prn.FontSize := pfs10cpi;
Prn.SendData('IP - GOURMET versao 2014================'+ln);
Prn.SendData(dm.EmpresaRazaoSocial.AsString+ln);
Prn.SendData('========================================'+ln);
Prn.SendData('VENDA: '+ dm.VendasCodigo.AsString + ' | ' + DateToStr(date) +' | '+ TimeToStr(time)+ln);
if dm.VendasTipo.AsString = 'MESA' Then
Prn.SendData('COD.MESA: '+ dm.VendasCodMESA.AsString+ln)
else if dm.VendasTipo.AsString = 'ENTREGA' Then
Prn.SendData('COD.ENTREGA: '+ dm.VendasCodMESA.AsString+ln)
else if dm.VendasTipo.AsString = 'BALCAO' Then
Prn.SendData('COD.BALCAO: '+ dm.VendasCodMESA.AsString+ln);
Prn.SendData('TIPO VENDA: '+ dm.VendasTipo.AsString + ' ' + dm.VendasMesa.AsString+ln);
if dm.VendasTipo.AsString = 'BALCAO' then
Prn.SendData('CLIENTE: '+ dm.VendasCliente.AsString+ln);
if dm.VendasTipo.AsString = 'ENTREGA' then
begin
Prn.SendData('CLIENTE: '+ dm.VendasCliente.AsString+ln);
Prn.SendData('TELEFONE: '+ dm.VendasTelefone.AsString+ln);
Prn.SendData('END.: '+ dm.VendasEndereco.AsString+ln);
Prn.SendData('BAIRRO: '+ dm.VendasBairro.AsString+ln);
Prn.SendData('NRO. / COMP.:'+ dm.VendasNumero.AsString + ' | ' + dm.VendasComplemento.AsString+ln);
Prn.SendData('OBS1.:'+ dm.VendasObservacoes.AsString+ln);
Prn.SendData('OBS2.:'+ dm.VendasObsEntrega.AsString+ln);
end;
if dm.VendasTipo.AsString = 'MESA' then
prn.SendData('GARÇOM.: ' + FmTouch.nomegarcom+ln);
Prn.SendData('===================ITENS================'+ln);
relacionamento;
dm.ItensVendas.First;
while not dm.ItensVendas.Eof do
begin
linha1 := '';
linha2 := '';
linha3 := '';
linha4 := '';
linha5 := '';
linha6 := '';
linha7 := '';
linha8 := '';
linha9 := '';
linha10 := '';
tmdesc := Length(dm.ItensVendasDescricaoImpressao.AsString);
qtdelinha := tmdesc / 40;
if qtdelinha<= 1 then
linha1 := dm.ItensVendasDescricaoImpressao.AsString
else if (qtdelinha > 1) and (qtdelinha <=2) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
end
else if (qtdelinha >2) and (qtdelinha <=3) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
end
else if (qtdelinha >3) and (qtdelinha <=4) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
end
else if (qtdelinha >4) and (qtdelinha <=5) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
end
else if (qtdelinha >5) and (qtdelinha <=6) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
end
else if (qtdelinha >6) and (qtdelinha <=7) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
end
else if (qtdelinha >7) and (qtdelinha <=8) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
linha8 := copy(dm.ItensVendasDescricaoImpressao.AsString, 281, 40);
end
else if (qtdelinha >8) and (qtdelinha <=9) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
linha8 := copy(dm.ItensVendasDescricaoImpressao.AsString, 281, 40);
linha9 := copy(dm.ItensVendasDescricaoImpressao.AsString, 321, 40);
end
else if (qtdelinha >8) and (qtdelinha <=9) then
begin
linha

Jamil Fonseca

Jamil Fonseca
Responder

Gostei + 1

Mais Posts

07/01/2014

Leonardo Xavier

Amanhã te trago o meu script que eu fiz com esta função, ja prontinha.
Responder

Gostei + 0

08/01/2014

Leonardo Xavier

Somente uma pergunta qual tipo de impressora você esta utilizando em sua aplicação? Generic/text?
Responder

Gostei + 0

08/01/2014

Josenildo Rosa

O Leonardo desde já agradeço pela ajuda, ainda não defini qual impressora irei usar se voce puder me dar a dica de qual modelo também agradeço, eu estava pensando em usar a Elgin Vox, Daruma DR700 ou Bematech MP-20, mas estou em dúvida .

Detalhe que esqueci de mencionar, uso Delphi 7 e Firebird 2.1

Somente uma pergunta qual tipo de impressora você esta utilizando em sua aplicação? Generic/text?
Responder

Gostei + 0

08/01/2014

Silvio Morelo

Eu utilizo as impressoras DIEBOLD e nunca deram problema, posso te passar a procedure que eu utilizo para imprimir.
Responder

Gostei + 0

08/01/2014

Josenildo Rosa

Morelo qualquer ajuda será bem vinda se puder me passar a procedure que faz imprimir eu agradeço.

Eu utilizo as impressoras DIEBOLD e nunca deram problema, posso te passar a procedure que eu utilizo para imprimir.
Responder

Gostei + 0

11/01/2014

Josenildo Rosa

E aí pessoal ninguém vai poder me ajudar ?
Responder

Gostei + 0

11/01/2014

Josenildo Rosa

Leonardo boa noite, Estou aguardando a função que ficou de me enviar.

Amanhã te trago o meu script que eu fiz com esta função, ja prontinha.
Responder

Gostei + 0

27/09/2014

Tânia Luiz

Bom dia, Morelo, poderia me ajudar, tenho uma Diebold, está imprimindo , só que o texto não fica centralizado no cupom, fica à esquerda....sabe como posso resolver?
Obrigada. Tânia
Responder

Gostei + 0

27/09/2014

Mauricio Rodrigues

use o writeln 100% nativo delphi
Responder

Gostei + 0

28/09/2014

Deivison Melo

Inclua na seção uses: Printers
Já vimos em outra dica como imprimir um memo acessando a
impressora como se fosse um arquivo. Aqui usaremos outra
técnica. Vamos usar o objeto Printer e "desenhar" na
impressora usando Canvas. Esta técnica, dentre outras coisas,
nos permite controlar:

- Salto de página;
- Espaçamento entre linhas;
- Margens, etc.

Veja esta rotina:

procedure ImprimirMemoComCanvas(Memo: TMemo);
const
cEspacoLinha = 5;
cMargemSuperior = 50;
cMargemEsquerda = 30;
var
AlturaLinha, Y, I: integer;
begin

Printer.BeginDoc;
try
{ Usa na impressora a mesma fonte do memo }
Printer.Canvas.Font.Assign(Memo.Font);

AlturaLinha := Printer.Canvas.TextHeight('Tg');

Y := cMargemSuperior;
for I := 0 to Memo.Lines.Count -1 do begin

if Y > Printer.PageHeight then begin
Printer.NewPage;
Y := cMargemSuperior;
end;

Printer.Canvas.TextOut(cMargemEsquerda, Y, Memo.Lines[I]);

Y := Y + AlturaLinha + cEspacoLinha;
end;
finally
Printer.EndDoc;
end;
end;

É um exemplo simples, mas funcional. Para testar chame esta
rotina passando o objeto TMemo como parâmetro. Exemplo:

ImprimirMemoComCanvas(Memo1);

Observações

A grande vantagem em usar o objeto Printer é que ele nos dá total liberdade para desenhar na impressora. Podemos, por exemplo, desenhar elipses, retângulos, etc. A principal desvantagem é que o programador precisa trabalhar muito para obter a impressão desejada. Mas às vezes vale a pena!
Autor: Daniel P. Guimarães
Home-page: www.tecnobyte.com.br
Responder

Gostei + 0

16/07/2015

Frank Silva

Boa Noite, Leonardo. Tudo bem? Se puder me passar tb esse script, estou tendo muita dificuldade, comecei agora a programar em Delphi e ainda tenho muitas dificuldades.
Obrigado
Responder

Gostei + 0

17/07/2015

Jamil Fonseca

ta ai como fazer pra imprimir em qualquer impressora existente no mercado tanto usb como serial ou paralela vc precisa da unita CharPrinter pode conseguir na internet ou me passe seu email que te envio vou postar ela inteira aqui

procedure TFmImpressao.btnbalcaoClick(Sender: TObject);
var prn:TAdvancedPrinter;
ln, linha1, linha2, linha3, linha4, linha5, linha6, linha7, linha8, linha9, linha10, tamanho: string;
tmdesc:integer;
qtdelinha: currency;
begin
ln := #13 + #10;
SetDefaultPrinter(simpbalcao);
prn := TAdvancedPrinter.Create;
Prn.OpenDoc('CUPOM DE VENDA');
prn.FontSize := pfs10cpi;
Prn.SendData('IP - GOURMET versao 2014================'+ln);
Prn.SendData(dm.EmpresaRazaoSocial.AsString+ln);
Prn.SendData('========================================'+ln);
Prn.SendData('VENDA: '+ dm.VendasCodigo.AsString + ' | ' + DateToStr(date) +' | '+ TimeToStr(time)+ln);
if dm.VendasTipo.AsString = 'MESA' Then
Prn.SendData('COD.MESA: '+ dm.VendasCodMESA.AsString+ln)
else if dm.VendasTipo.AsString = 'ENTREGA' Then
Prn.SendData('COD.ENTREGA: '+ dm.VendasCodMESA.AsString+ln)
else if dm.VendasTipo.AsString = 'BALCAO' Then
Prn.SendData('COD.BALCAO: '+ dm.VendasCodMESA.AsString+ln);
Prn.SendData('TIPO VENDA: '+ dm.VendasTipo.AsString + ' ' + dm.VendasMesa.AsString+ln);
if dm.VendasTipo.AsString = 'BALCAO' then
Prn.SendData('CLIENTE: '+ dm.VendasCliente.AsString+ln);
if dm.VendasTipo.AsString = 'ENTREGA' then
begin
Prn.SendData('CLIENTE: '+ dm.VendasCliente.AsString+ln);
Prn.SendData('TELEFONE: '+ dm.VendasTelefone.AsString+ln);
Prn.SendData('END.: '+ dm.VendasEndereco.AsString+ln);
Prn.SendData('BAIRRO: '+ dm.VendasBairro.AsString+ln);
Prn.SendData('NRO. / COMP.:'+ dm.VendasNumero.AsString + ' | ' + dm.VendasComplemento.AsString+ln);
Prn.SendData('OBS1.:'+ dm.VendasObservacoes.AsString+ln);
Prn.SendData('OBS2.:'+ dm.VendasObsEntrega.AsString+ln);
end;
if dm.VendasTipo.AsString = 'MESA' then
prn.SendData('GARÇOM.: ' + FmTouch.nomegarcom+ln);
Prn.SendData('===================ITENS================'+ln);
relacionamento;
dm.ItensVendas.First;
while not dm.ItensVendas.Eof do
begin
linha1 := '';
linha2 := '';
linha3 := '';
linha4 := '';
linha5 := '';
linha6 := '';
linha7 := '';
linha8 := '';
linha9 := '';
linha10 := '';
tmdesc := Length(dm.ItensVendasDescricaoImpressao.AsString);
qtdelinha := tmdesc / 40;
if qtdelinha<= 1 then
linha1 := dm.ItensVendasDescricaoImpressao.AsString
else if (qtdelinha > 1) and (qtdelinha <=2) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
end
else if (qtdelinha >2) and (qtdelinha <=3) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
end
else if (qtdelinha >3) and (qtdelinha <=4) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
end
else if (qtdelinha >4) and (qtdelinha <=5) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
end
else if (qtdelinha >5) and (qtdelinha <=6) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
end
else if (qtdelinha >6) and (qtdelinha <=7) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
end
else if (qtdelinha >7) and (qtdelinha <=8) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
linha8 := copy(dm.ItensVendasDescricaoImpressao.AsString, 281, 40);
end
else if (qtdelinha >8) and (qtdelinha <=9) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
linha8 := copy(dm.ItensVendasDescricaoImpressao.AsString, 281, 40);
linha9 := copy(dm.ItensVendasDescricaoImpressao.AsString, 321, 40);
end
else if (qtdelinha >8) and (qtdelinha <=9) then
begin
linha1 := copy(dm.ItensVendasDescricaoImpressao.AsString, 0, 40);
linha2 := copy(dm.ItensVendasDescricaoImpressao.AsString, 41, 40);
linha3 := copy(dm.ItensVendasDescricaoImpressao.AsString, 81, 40);
linha4 := copy(dm.ItensVendasDescricaoImpressao.AsString, 121, 40);
linha5 := copy(dm.ItensVendasDescricaoImpressao.AsString, 161, 40);
linha6 := copy(dm.ItensVendasDescricaoImpressao.AsString, 201, 40);
linha7 := copy(dm.ItensVendasDescricaoImpressao.AsString, 241, 40);
linha8 := copy(dm.ItensVendasDescricaoImpressao.AsString, 281, 40);
linha9 := copy(dm.ItensVendasDescricaoImpressao.AsString, 321, 40);
linha10 := copy(dm.ItensVendasDescricaoImpressao.AsString, 361, 40);
end;
if dm.ItensVendasEmbalagem.AsInteger = 0 then
tamanho := dm.ItensVendasTm.AsString
else
tamanho := '';
Prn.SendData(FormatCurr('#,###,##0.000', dm.ItensVendasQtde.AsCurrency)+' '+tamanho+' '+FormatCurr('#,###,##0.00', dm.ItensVendasTotal.AsCurrency)+ln);
Prn.SendData(linha1+ln);
if linha2 <> '' then
Prn.SendData(linha2+ln);
if linha3 <> '' then
Prn.SendData(linha3+ln);
if linha4 <> '' then
Prn.SendData(linha4+ln);
if linha5 <> '' then
Prn.SendData(linha5+ln);
if linha6 <> '' then
Prn.SendData(linha6+ln);
if linha7 <> '' then
Prn.SendData(linha7+ln);
if linha8 <> '' then
Prn.SendData(linha8+ln);
if linha9 <> '' then
Prn.SendData(linha9+ln);
if linha10 <> '' then
Prn.SendData(linha10+ln);
if dm.ItensVendasOpcionalExtra.AsString <> '' then
Prn.SendData(dm.ItensVendasOpcionalExtra.AsString +ln);
Prn.SendData('----------------------------------------'+ln);
dm.ItensVendas.Next;
end;
Prn.SendData('SUBTOTAL PEDIDO..: R$ '+ FormatCurr('#,###,##0.00', dm.VendasSubtotal.AsCurrency)+ln);
Prn.SendData('DESCONTO.........: R$ '+ FormatCurr('#,###,##0.00', dm.VendasDesconto.AsCurrency)+ln);
Prn.SendData('TX. ENTREGA......: R$ '+ FormatCurr('#,###,##0.00', dm.VendastxEntrega.AsCurrency)+ln);
if dm.VendastxServico.AsCurrency > 0 then
Prn.SendData('TX. SERVICO......: R$ '+ FormatCurr('#,###,##0.00', dm.VendastxServico.AsCurrency)+ln);
Prn.SendData('TOTAL DO PEDIDO..: R$ '+ FormatCurr('#,###,##0.00', dm.VendasTotal.AsCurrency)+ln);
if dm.VendasNroPessoas.AsInteger > 1 then
Prn.SendData('TOTAL POR PESSOA.: R$ '+ FormatCurr('#,###,##0.00', dm.VendasTotal.AsCurrency / dm.VendasNroPessoas.AsInteger)+ln);
if dm.VendasForma1.AsString <> '' then
Prn.SendData('PGTO.: R$ '+ dm.VendasForma1.AsString + ' ' + FormatCurr('#,###,##0.00', dm.VendasValorForma1.AsCurrency)+ln);
if dm.VendasForma2.AsString <> '' then
Prn.SendData('PGTO.: R$ '+ dm.VendasForma2.AsString + ' ' + FormatCurr('#,###,##0.00', dm.VendasValorForma2.AsCurrency)+ln);
if dm.VendasForma3.AsString <> '' then
Prn.SendData('PGTO.: R$ '+ dm.VendasForma3.AsString + ' ' + FormatCurr('#,###,##0.00', dm.VendasValorForma3.AsCurrency)+ln);
if dm.VendasForma4.AsString <> '' then
Prn.SendData('PGTO.: R$ '+ dm.VendasForma4.AsString + ' ' + FormatCurr('#,###,##0.00', dm.VendasValorForma4.AsCurrency)+ln);
Prn.SendData('TROCO...........: R$ '+ FormatCurr('#,###,##0.00', dm.VendasTroco.AsCurrency)+ln);
Prn.SendData(dm.EmpresaFrase1.AsString+ln);
Prn.SendData(dm.EmpresaFrase2.AsString+ln);
Prn.SendData(ln);
Prn.SendData(ln);
Prn.SendData(ln);
Prn.SendData(ln);
Prn.SendData(ln);
Prn.SendData(ln);
Prn.SendData(ln);
Prn.CloseDoc;
end;
Responder

Gostei + 0

17/07/2015

Jamil Fonseca

//---------------------------------------------------------------
// CharPrinter.pas - Tratamento de impressoras em modo caractere
//---------------------------------------------------------------
// Autor : Fernando Allen Marques de Oliveira
// Dezembro de 2000.
//
// TPrinterStream : classe derivada de TStream para enviar dados
// diretamente para o spool da impressora sele-
// cionada.
//
// TCharPrinter : Classe base para implementação de impressoras.
// não inclui personalização para nenhuma impres-
// sora específica, envia dados sem formatação.
//
// Modificado em 20/05/2003 - Compatibilização com diretivas padrão do Delphi 7
// Modificado por Jamil Alves Fonseca Outubro de 2011.

unit CharPrinter;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Printers, WinSpool;

type
{ Stream para enviar caracteres à impressora atual }
TPrinterStream = class (TStream)
private
fPrinter : TPrinter;
fHandle : THandle;
fTitle : String;
procedure CreateHandle;
procedure FreeHandle;
public
constructor Create (aPrinter: TPrinter; aTitle : String);
destructor Destroy; override;
function Write (const Buffer; Count : Longint): Longint; override;
property Handle : THandle read fHandle;
end;

TCharPrinter = class(TObject)
private
{ Private declarations }
fStream : TStream;
protected
{ Protected declarations }
public
{ Public declarations }
published
{ Published declarations }
constructor Create; virtual;
destructor Destroy; override;
procedure OpenDoc (aTitle : String); virtual;
procedure SendData (aData : String);
procedure CloseDoc; virtual;
property PrintStream : TStream read fStream;

end;

// Definições para TAdvancedPrinter //

TprtLang = (lngEPFX,lngESCP2,lngHPPCL);
TprtFontSize = (pfs5cpi,pfs10cpi,pfs12cpi,pfs17cpi,pfs20cpi);
TprtTextStyle = (psBold,psItalic,psUnderline);
TprtTextStyles = set of TprtTextStyle;

TAdvancedPrinter = class (TCharPrinter)
private
fLang : TprtLang;
fFontSize : TprtFontSize;
fTextStyle : TprtTextStyles;
function GetLang : TprtLang;
function GetFontSize : TprtFontSize;
procedure SetFontSize (size : TprtFontSize);
procedure SetTextStyle (styles : TprtTextStyles);
function GetTextStyle : TprtTextStyles;
procedure UpdateStyle;
procedure Initialize;
function Convert (s : string) : string;
public
procedure CR;
procedure LF; overload;
procedure LF (Lines : integer); overload;
procedure CRLF;
procedure FF;
procedure Write (txt : string);
procedure WriteLeft (txt, fill : string; size : integer);
procedure WriteRight (txt, fill : string; size : integer);
procedure WriteCenter(txt, fill : string; size : integer);
procedure WriteRepeat(txt : string; quant : integer);
procedure SetLang (lang : TprtLang);
published
constructor Create; override;
procedure OpenDoc (aTitle : String); override;
property Language : TprtLang read GetLang write SetLang;
property FontSize : TprtFontSize read GetFontSize write SetFontSize;
property TextStyle : TprtTextStyles read GetTextStyle write SetTextStyle;
end;

procedure Register;

implementation

procedure Register;
begin
{ RegisterComponents('AeF', [TCharPrinter]);}
end;

{ =================== }
{ = TPrinterStream = }
{ =================== }

constructor TPrinterStream.Create (aPrinter : TPrinter; aTitle : String);
begin
inherited Create;
fPrinter := aPrinter;
fTitle := aTitle;
CreateHandle;
end;

destructor TPrinterStream.Destroy;
begin
FreeHandle;
inherited;
end;

procedure TPrinterStream.FreeHandle;
begin
if fHandle <> 0 then
begin
EndPagePrinter (fHandle);
EndDocPrinter (fHandle);
ClosePrinter (Handle);
fHandle := 0;
end;
end;

procedure TPrinterStream.CreateHandle;
type
DOC_INFO_1 = packed record
pDocName : PChar;
pOutputFile : PChar;
pDataType : PChar;
end;
var
aDevice,
aDriver,
aPort : array[0..255] of Char;
aMode : Cardinal;
DocInfo : DOC_INFO_1;
begin
DocInfo.pDocName := nil;
DocInfo.pOutputFile := nil;
DocInfo.pDataType := 'RAW';

FreeHandle;
if fHandle = 0 then
begin
fPrinter.GetPrinter (aDevice, aDriver, aPort, aMode);
if OpenPrinter (aDevice, fHandle, nil)
then begin
DocInfo.pDocName := PChar(fTitle);
if StartDocPrinter (fHandle, 1, @DocInfo) = 0
then begin
ClosePrinter (fHandle);
fHandle := 0;
end else
if not StartPagePrinter (fHandle)
then begin
EndDocPrinter (fHandle);
ClosePrinter (fHandle);
fHandle := 0;
end;
end;
end;
end;

function TPrinterStream.Write (const Buffer; Count : Longint) : Longint;
var
Bytes : Cardinal;
begin
WritePrinter (Handle, @Buffer, Count, Bytes);
Result := Bytes;
end;

{ ================= }
{ = TCharPrinter = }
{ ================= }

constructor TCharPrinter.Create;
begin
inherited Create;
fStream := nil;
end;

destructor TCharPrinter.Destroy;
begin
if fStream <> nil
then fStream.Free;
inherited;
end;

procedure TCharPrinter.OpenDoc (aTitle : String);
begin
if fStream = nil
then fStream := TPrinterStream.Create (Printer, aTitle);
end;

procedure TCharPrinter.CloseDoc;
begin
if fStream <> nil
then begin
fStream.Free;
fStream := nil;
end;
end;

procedure TCharPrinter.SendData (aData : String);
var
Data : array[0..255] of char;
cnt : integer;
begin
for cnt := 0 to length(aData) - 1 do
Data[cnt] := aData[cnt+1];

fStream.Write (Data, length(aData));
end;

{ ===================== }
{ = TAdvancedPrinter = }
{ ===================== }

procedure TAdvancedPrinter.SetLang (lang : TprtLang);
begin
fLang := lang;
end;

function TAdvancedPrinter.GetLang : TprtLang;
begin
result := fLang;
end;

procedure TAdvancedPrinter.SetFontSize (size : TprtFontSize);
begin
fFontSize := size;
UpdateStyle;
end;

function TAdvancedPrinter.GetFontSize : TprtFontSize;
begin
result := fFontSize;
UpdateStyle;
end;

procedure TAdvancedPrinter.SetTextStyle (styles : TprtTextStyles);
begin
fTextStyle := styles;
UpdateStyle;
end;

function TAdvancedPrinter.GetTextStyle : TprtTextStyles;
begin
result := fTextStyle;
UpdateStyle;
end;

procedure TAdvancedPrinter.UpdateStyle;
var
cmd : string;
i : byte;
begin
cmd := '';
case fLang of
lngESCP2, lngEPFX : begin
i := 0;
Case fFontSize of
pfs5cpi : i := 32;
pfs10cpi : i := 0;
pfs12cpi : i := 1;
pfs17cpi : i := 4;
pfs20cpi : i := 5;
end;
if psBold in fTextStyle then i := i + 8;
if psItalic in fTextStyle then i := i + 64;
if psUnderline in fTextStyle then i := i + 128;
cmd := #27'!'+chr(i);
end;
lngHPPCL : begin
Case fFontSize of
pfs5cpi : cmd := #27'(s5H';
pfs10cpi : cmd := #27'(s10H';
pfs12cpi : cmd := #27'(s12H';
pfs17cpi : cmd := #27'(s17H';
pfs20cpi : cmd := #27'(s20H';
end;
if psBold in fTextStyle
then cmd := cmd + #27'(s3B'
else cmd := cmd + #27'(s0B';
if psItalic in fTextStyle
then cmd := cmd + #27'(s1S'
else cmd := cmd + #27'(s0S';
if psUnderline in fTextStyle
then cmd := cmd + #27'&d0D'
else cmd := cmd + #27'&d@';
end;
end;
SendData(cmd);
end;

procedure TAdvancedPrinter.Initialize;
begin
case fLang of
lngEPFX : SendData (#27'@'#27'2'#27'P'#18);
lngESCP2 : SendData (#27'@'#27'O'#27'2'#27'C0'#11#27'!'#0);
lngHPPCL : SendData (#27'E'#27'&l2A'#27'&l0O'#27'&l6D'#27'(s4099T'#27'(s0P'#27'&k0S'#27'(s0S');
end;
end;

function TAdvancedPrinter.Convert (s : string) : string;
const
accent : string = 'ãàáäâèéëêìíïîõòóöôùúüûçÃÀÁÄÂÈÉËÊÌÍÏÎÕÒÓÖÔÙÚÜÛÇ';
noaccent : string = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';
var
i : integer;
begin
for i := 1 to length(accent) do
While Pos(accent[i],s) > 0 do s[Pos(accent[i],s)] := noaccent[i];
result := s;
end;

constructor TAdvancedPrinter.Create;
begin
inherited Create;
fLang := lngESCP2;
fFontSize := pfs10cpi;
fTextStyle := [];
end;

procedure TAdvancedPrinter.OpenDoc (aTitle : String);
begin
inherited OpenDoc (aTitle);
Initialize;
end;

procedure TAdvancedPrinter.CR;
begin
SendData (#13);
end;

procedure TAdvancedPrinter.LF;
begin
SendData (#10);
end;

procedure TAdvancedPrinter.LF (Lines : integer);
begin
while lines > 0 do begin
SendData(#10); dec(lines);
end;
end;

procedure TAdvancedPrinter.CRLF;
begin
SendData (#13#10);
end;

procedure TAdvancedPrinter.FF;
begin
SendData(#12);
end;

procedure TAdvancedPrinter.Write (txt : string);
begin
txt := Convert (txt);
SendData (txt);
end;

procedure TAdvancedPrinter.WriteLeft (txt, fill : string; size : integer);
begin
txt := Convert(txt);
while Length(txt) < size do txt := txt + fill;
SendData (Copy(txt,1,size));
end;

procedure TAdvancedPrinter.WriteRight (txt, fill : string; size : integer);
begin
txt := Convert(txt);
while Length(txt) < size do txt := fill + txt;
SendData (Copy(txt,Length(txt)-size+1,size));
end;

procedure TAdvancedPrinter.WriteCenter(txt, fill : string; size : integer);
begin
txt := Convert(txt);
while Length(txt) < size do txt := fill + txt + fill;
SendData (Copy(txt,(Length(txt)-size) div 2 + 1,size));
end;

procedure TAdvancedPrinter.WriteRepeat(txt : string; quant : integer);
var
s : string;
begin
s := '';
txt := Convert(txt);
while quant > 0 do begin
s := s + txt;
dec(quant);
end;
SendData (s);
end;


end.
Responder

Gostei + 0

17/07/2015

Frank Silva

Obrigado, vou tentar agora.
Responder

Gostei + 0

17/07/2015

Lucas Ramos

Josenildo, pode utilizar como se fosse gravar um arquivo txt passando a porta da impressora como parâmetro, ou no caso de impressoras como Bematech, Daruma utilizar a própria DLL, mas acredito que o trabalho seja maior.

procedure TForm1.Imprimir(pTexto: TStringList);
var
     lCont   : Integer;
     lPorta  : String;
     lArquivo: TextFile;
begin
     lPorta := 'COM1';
     AssignFile(lArquivo,lPorta);
     Reset(lArquivo);

     for lCont := 0 to pTexto.Count - 1 do
         WriteLn(lArquivo,pTexto[lCont]);

     CloseFile(lArquivo);
end;
Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar