valSistemasDelphi 0 Posted August 11, 2020 Report Share Posted August 11, 2020 Fala Galera beleza!? Sempre usei componentes para imprimir relatórios!!!! Mais queria fazer algo meio na unha sem componentes, procurei na internet algo mais não achei.. somente com componentes!!!! Quero que imprimi Texto do MEMO!!! Quero um código que faça isso!! Alguém sabe?? Quote Link to post Share on other sites
0 Jhonas 0 Posted August 11, 2020 Report Share Posted August 11, 2020 Quero que imprimir Texto do MEMO!!! Quero um código que faça isso!! procurei na internet algo mais não achei.. somente com componentes!!!! Amigo, na internet ta cheio de exemplos: http://www.planetadelphi.com.br/dica/7146/-imprimir-conteudo-de-um-memo-(simples-e-facil)- ou https://www.google.com.br/search?source=hp&ei=oVE0X8DDEIHH5OUP8KKiqAY&q=imprimir+memo+delphi&o que=imprimir+memo+&gs_lcp=CgZwc3ktYWIQARgAMgIIADIGCAAQFhAeMgYIABAWEB4yBggAEBYQHjIGCAAQFhAeMgYIABAWEB4yBggAEBYQHjoICAAQsQMQgwE6BQgAELEDOggIABAWEAoQHlDSC1jSH2D6LmgAcAB4AIABsAGIAcgOkgEEMS4xNJgBAKABAaoBB2d3cy13aXqwAQA&sclient=psy-ab Obs: Na impressão do Memo, o texto vai ficar meio bagunçado ( justificação ) ... mas voce pode usar essa rotina para justificar o texto, para ficar mais bonito Abraço Quote Link to post Share on other sites
0 valSistemasDelphi 0 Posted August 11, 2020 Author Report Share Posted August 11, 2020 Valeu Jonas por responder!! Consegui Com essa Rotina!! procedure TForm1.Button1Click(Sender: TObject); var I: integer; begin //Inicia a impressão Printer.Canvas.font.Name := 'Courier new'; Printer.Canvas.font.size := 15; Printer.BeginDoc; Printer.Title := 'Emissor'; //Conta quantidades de linhas no Memo for I := 0 to Memo1.Lines.Count - 1 do begin //Imprime as linhas Printer.Canvas.TextOut(1,(I - 1)*Printer.Canvas.TextHeight('Emissor'),Memo1.Lines[I - 1]); end; //Termina a impressão Printer.EndDoc; Teria como colocar algo a mais nesse código para Justificar o texto ? Ou somente com a Função? Quote Link to post Share on other sites
0 Jhonas 0 Posted August 12, 2020 Report Share Posted August 12, 2020 Teria como colocar algo a mais nesse código para Justificar o texto ? Ou somente com a Função? Seria isso: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Memo2: TMemo; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function StrPad(AValue: String; const ALength: Integer; const ASide: TAlignment): String; begin AValue := Trim(AValue); if Length(AValue) > ALength then AValue := Copy(AValue,1,ALength); case ASide of taLeftJustify: while Length(AValue) < ALength do AValue := AValue + ' '; taRightJustify: while Length(AValue) < ALength do AValue := ' ' + AValue; taCenter: while Length(AValue) < ALength do if (Length(AValue) mod 2)= 0 then AValue := AValue + ' ' else AValue := ' ' + AValue; end; Result := AValue; end; // tamanho da linha = 80 caracteres procedure TForm1.Button1Click(Sender: TObject); var i, j : integer; begin showmessage(inttostr(MEMO1.LINES.Count)); for j := 1 to MEMO1.LINES.Count do begin if Length(MEMO1.LINES.Strings[j]) < 80 then MEMO2.LINES.Append(StrPad(MEMO1.LINES.Strings[j],80,TACENTER)) else begin MEMO2.LINES.Append(StrPad(MEMO1.LINES.Strings[j],80,TACENTER)); MEMO2.LINES.Append(StrPad(copy(MEMO1.LINES.Strings[j],81,80),80,taLeftJustify)); end; end; //Inicia a impressão Printer.Canvas.font.Name := 'Courier new'; Printer.Canvas.font.size := 15; Printer.BeginDoc; Printer.Title := 'Emissor'; //Conta quantidades de linhas no Memo for I := 0 to Memo2.Lines.Count - 1 do begin //Imprime as linhas Printer.Canvas.TextOut(1,(I - 1)*Printer.Canvas.TextHeight('Emissor'),Memo2.Lines[I - 1]); end; //Termina a impressão Printer.EndDoc; end; end. abraço Quote Link to post Share on other sites
0 valSistemasDelphi 0 Posted August 12, 2020 Author Report Share Posted August 12, 2020 Tá dando erro nesse taLeftJustify: Quote Link to post Share on other sites
0 Jhonas 0 Posted August 12, 2020 Report Share Posted August 12, 2020 case ASide of taLeftJustify: Substitua o ponto e virgula por dois pontos abraço Quote Link to post Share on other sites
0 valSistemasDelphi 0 Posted August 12, 2020 Author Report Share Posted August 12, 2020 (edited) No memo está saindo desta forma.. e na Impressão sai ao Lado Esquerdo Será que tem que configurar para o modelo da impressora, uso aqui HP 390series Percebi que se eu Colocar no Próprio Código do Memo.lines.Add, Alinhado ao Meio, ele até que imprimi meio centralizado na Folha!!! Mais quero que ele faça isso de forma automática... Creio que terá que configurar no próprio código algo relaciona a tamanho da Folha e etc.. Edited August 12, 2020 by valSistemasDelphi errei Quote Link to post Share on other sites
0 Jhonas 0 Posted August 12, 2020 Report Share Posted August 12, 2020 Se voce tivesse colocado isso ( Impressão ) no começo eu diria que voce não deve usar justificação de texto mas sim tabulação de texto. Voce vai tabular o texto no Memo, e depois fazer a impressão do Memo tabulado exemplo: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; ComboBox1: TComboBox; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); Procedure Memo_Print(Conteudo:TStrings); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation Uses Printers; {$R *.dfm} procedure TForm1.FormActivate(Sender: TObject); var i : Integer; begin // Pegar o nome de todas as Fontes e colocar no Combobox for i := 0 to Screen.Fonts.Count - 1 do ComboBox1.Items.Add(Screen.Fonts.Strings[i]); // Deixar o Combobox Invisivel ComboBox1.Visible := false; end; Procedure TForm1.Memo_Print(Conteudo:TStrings); Var MemoFile : TextFile; P : Integer; Begin AssignPrn(MemoFile); Rewrite(MemoFile); For P := 0 to Conteudo.Count - 1 do Writeln(MemoFile,Conteudo.Strings[P]); CloseFile(MemoFile); end; procedure TForm1.Button1Click(Sender: TObject); var i : integer; TabsSet : Array[0..2] of DWord; begin // Pegar o Nome da Fonte do Memo ( Courrier New ) Memo1.Font.Name := ComboBox1.Items.Strings[16]; // Mudar Tamanho da Fonte Memo1.Font.Size := 10; // Fazendo tabulacoes em um MEMO // tabs diferentes TabsSet[0] := 60; TabsSet[1] := 180; TabsSet[2] := 300; Memo1.Perform(EM_SETTABSTOPS,3,Integer(@TabsSet)); // colocando valores no memo for i := 1 to 9 do // 9 linhas no Memo Memo1.Lines.Add('Linha '+IntToStr(i)+#9'Opção '+IntToStr(i)+#9'Teste'); Memo1.SelStart := 0; if MessageDlg('Deseja Imprimir o CUPOM ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin Memo_Print(Memo1.Lines); end else begin MessageDlg('OPERAÇÃO CANCELADA! ', mtInformation, [mbOK], 0); // volta ao normal o texto no Memo ( sem espaçamento ) Memo1.Perform(EM_SETTABSTOPS,0,0); end; end; end. Obs: Execute esse programa sem alterar nada e veja o resultado. Tente entender como funciona esse código Fazendo algumas alterações no código, voce consegue fazer o que está querendo. abraço Quote Link to post Share on other sites
0 valSistemasDelphi 0 Posted August 12, 2020 Author Report Share Posted August 12, 2020 Quote Link to post Share on other sites
0 Jhonas 0 Posted August 12, 2020 Report Share Posted August 12, 2020 type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; ComboBox1: TComboBox; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); Procedure Memo_Print(Conteudo:TStrings); private { Private declarations } public { Public declarations } end; Obs: Se voce copiar o codigo todo não vai dar erro abraço Quote Link to post Share on other sites
0 valSistemasDelphi 0 Posted August 12, 2020 Author Report Share Posted August 12, 2020 (edited) Cara o Código é show.. Mais infelizmente a impressão sempre sai a esquerda!! Deixa perguntar Sabe uma forma de Definir que e Papel a 4??? Via código!!! Os componentes de Relatórios já são definidos assim! Creio que está faltando isso!! Edited August 12, 2020 by valSistemasDelphi errei Quote Link to post Share on other sites
0 Jhonas 0 Posted August 12, 2020 Report Share Posted August 12, 2020 Veja a alteração no código da impressão unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; ComboBox1: TComboBox; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); Procedure Memo_Print(Conteudo:TStrings); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation Uses Printers, QRPrntr; {$R *.dfm} procedure TForm1.FormActivate(Sender: TObject); var i : Integer; begin // Pegar o nome de todas as Fontes e colocar no Combobox for i := 0 to Screen.Fonts.Count - 1 do ComboBox1.Items.Add(Screen.Fonts.Strings[i]); // Deixar o Combobox Invisivel ComboBox1.Visible := false; end; Procedure TForm1.Memo_Print(Conteudo:TStrings); Var MemoFile : TextFile; P : Integer; PrintTeste: TQRPrinter; Begin PrintTeste := TQRPrinter.Create(Self); PrintTeste.PaperSize := A4; {os parâmetros podem ser A5, B5, Letter e outros} AssignPrn(MemoFile); Rewrite(MemoFile); For P := 0 to Conteudo.Count - 1 do Writeln(MemoFile,Conteudo.Strings[P]); CloseFile(MemoFile); end; procedure TForm1.Button1Click(Sender: TObject); var i : integer; TabsSet : Array[0..2] of DWord; begin // Pegar o Nome da Fonte do Memo ( Courrier New ) Memo1.Font.Name := ComboBox1.Items.Strings[16]; // Mudar Tamanho da Fonte Memo1.Font.Size := 10; // Fazendo tabulacoes em um MEMO // tabs diferentes TabsSet[0] := 60; TabsSet[1] := 180; TabsSet[2] := 300; Memo1.Perform(EM_SETTABSTOPS,3,Integer(@TabsSet)); // colocando valores no memo for i := 1 to 9 do // 9 linhas no Memo Memo1.Lines.Add('Linha '+IntToStr(i)+#9'Opção '+IntToStr(i)+#9'Teste'); Memo1.SelStart := 0; if MessageDlg('Deseja Imprimir o CUPOM ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then begin Memo_Print(Memo1.Lines); end else begin MessageDlg('OPERAÇÃO CANCELADA! ', mtInformation, [mbOK], 0); // volta ao normal o texto no Memo ( sem espaçamento ) Memo1.Perform(EM_SETTABSTOPS,0,0); end; end; end. Não esqueça de definir Uses Printers, QRPrntr; Obs: Se o código não funcionar tente esses https://www.google.com.br/search?source=hp&ei=hHU0X_WTLcTG5OUP3dyl4AM&q=mudar+tamanho+do+papel+delphi&o que=mudar+tamanho+do+papel+delphi&gs_lcp=CgZwc3ktYWIQAzIFCCEQoAE6BQgAELEDOggIABCxAxCDAToFCC4QsQM6CAguELEDEIMBOgIIADoCCC46BggAEBYQHjoHCCEQChCgAToICCEQFhAdEB5Q7g1YxERgwEpoAXAAeACAAfwBiAGaH5IBBjAuMjkuMpgBAKABAaoBB2d3cy13aXqwAQA&sclient=psy-ab&ved=0ahUKEwj15cKx45brAhVEI7kGHV1uCTwQ4dUDCAY&uact=5 abraço Quote Link to post Share on other sites
Question
valSistemasDelphi 0
Fala Galera beleza!?
Sempre usei componentes para imprimir relatórios!!!!
Mais queria fazer algo meio na unha sem componentes, procurei na internet algo mais não achei.. somente com componentes!!!!
Quero que imprimi Texto do MEMO!!!
Quero um código que faça isso!!
Alguém sabe??
Link to post
Share on other sites
11 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.