Etiqueta com Fast Report

28/12/2015

0

Bom dia.
Preciso fazer a impressão de etiquetas para papel Pimaco e gostaria de saber como faz pra definir o inicio da impressão a partir de uma linha especifica. Começar a imprimir a partir da terceira linha de impressão, por exemplo.
Obrigado!!
Raylan Zibel

Raylan Zibel

Responder

Post mais votado

06/01/2016

Fiz com array of array of string. Os primeiros registros vazios determinam a posição inicial para impressão.

//-----------------------------------------TABELA COM AS ETIQUETAS--------------------------------------------//  
type
  TEtiquetas = array of array of string;

//-----------------------------------------ROTINA DE IMPRESSÃO----------------------------------------------//  
procedure EtiquetaPimacoFast(Etiquetas: TEtiquetas);
{
uses DateUtils, frxClass, Math;
}
const
  TamFonte: Byte = 10;
  AlturaLinha: Byte = 15; // pixels // menor que 15 depende da fonte
  InchToPixel: Byte = 96; // 1 polegada
var
  x, y: Byte;
  i, j: Byte; 
  LinhaAtual: Byte;
  TotLinha, TotColuna: Byte;
  AlturaEtiqueta, LarguraEtiqueta: Double;
  MargemEsquerda, MargemDireita: Double;
  MargemSuperior, MargemInferior: Double;
  AlturaFolha, LarguraFolha: Double;
  Report: TfrxReport;
  Page: TfrxReportPage;
  Band: TfrxBand;
  Memo: TfrxMemoView;

  procedure novaPagina;
  begin
    // lendo ini // valores alternativos são de modelo A4->2x6 // valores em milímetros
    LarguraEtiqueta := (IniReadFlt('REPORT', 'LARGURA_ETIQUETA', 90.00));
    AlturaEtiqueta := (IniReadFlt('REPORT', 'ALTURA_ETIQUETA', 45.00));
    MargemSuperior := (IniReadFlt('REPORT', 'MARGEM_SUPERIOR', 10.00));
    MargemInferior := (IniReadFlt('REPORT', 'MARGEM_INFERIOR', 10.00));
    MargemEsquerda := (IniReadFlt('REPORT', 'MARGEM_ESQUERDA', 10.00));
    MargemDireita := (IniReadFlt('REPORT', 'MARGEM_DIREITA', 10.00));
    LarguraFolha := (IniReadFlt('REPORT', 'LARGURA_FOLHA', 210.00));
    AlturaFolha := (IniReadFlt('REPORT', 'ALTURA_FOLHA', 290.70));
    TotColuna := Floor(LarguraFolha - MargemEsquerda - MargemDireita) / LarguraEtiqueta);
    TotLinha := Floor((AlturaFolha - MargemSuperior - MargemInferior) / AlturaEtiqueta);
    // cria página
    Page := TfrxReportPage.Create(Report);
    Page.CreateUniqueName;
    Page.SetDefaults;
    // configura página
    Page.Width := LarguraFolha;
    Page.Height := AlturaFolha;
    Page.TopMargin := MargemSuperior;
    Page.BottomMargin := MargemInferior;
    Page.LeftMargin := MargemEsquerda;
    Page.RightMargin := MargemDireita;
    // converte pra pixels pra posicionar os MemoViews
    MargemEsquerda := MmToInch(MargemEsquerda) * InchToPixel;
    MargemSuperior := MmToInch(MargemSuperior) * InchToPixel;
    LarguraEtiqueta := MmToInch(LarguraEtiqueta) * InchToPixel;
    AlturaEtiqueta := MmToInch(AlturaEtiqueta) * InchToPixel;
    // cria banda na página
    Band := TfrxReportTitle.Create(Page);
    Band.CreateUniqueName;
    Band.Top := 0;
    Band.Height := Page.Height;
  end;

  procedure GravaMemo(Valor: string; Alinhamento: TfrxHAlign; Fonte: TFontStyles);
  begin
    // cria memo na banda da página
    Memo := TfrxMemoView.Create(Band);
    Memo.CreateUniqueName;
    // configura memo
    Memo.Text := Valor;
    Memo.Font.Size := TamFonte;
    Memo.Font.Style := Fonte;
    Memo.HAlign := Alinhamento;
    Memo.WordWrap := False;
    // memo é posicionado abaixo do memo anterior ((LinhaAtual - 1) * AlturaLinha)
    Inc(LinhaAtual);
    // primeira linha/coluna posiciona em margemesquerda/margemsuperior
    // demais linhas/colunas posicionam em margemesquerda+larguraetiqueta/margemsuperior+alturaetiqueta
    Memo.SetBounds(IfThen(j = 1, MargemEsquerda * j, MargemEsquerda + ((j - 1) * LarguraEtiqueta)), IfThen(i = 1, MargemSuperior + (i *
      LinhaAtual) + ((LinhaAtual - 1) * AlturaLinha), MargemSuperior + ((i - 1) * AlturaEtiqueta) + ((LinhaAtual - 1) * AlturaLinha)),
      LarguraEtiqueta, AlturaLinha);
  end;

begin
  try
    // cria report
    Report := TfrxReport.Create(Self);
    // configura preview do report
    with Report do
    begin
      Clear;
      PreviewOptions.ThumbnailVisible := True;
      PreviewOptions.ZoomMode := zmWholePage
    end;
    // pagina inicial
    novaPagina;
    x := 0;
    while x < Length(Etiquetas) do
    begin
      for i := 1 to TotLinha do
      begin
        if x = Length(Etiquetas) then
          Break;
        for j := 1 to TotColuna do
        begin
          if x = Length(Etiquetas) then
            Break;
          LinhaAtual := 0;
          for y := 0 to Length(Etiquetas[x]) - 1 do
          begin
            if y = 0 then // haCenter, fdBold
              GravaMemo(Etiquetas[x][y], haCenter, [fsBold])
            else // haLeft
              GravaMemo(Etiquetas[x][y], haLeft, []);
          end;
          Inc(x);
        end;
      end;
      Inc(x);
      // mais de uma página
      if x < Length(Etiquetas) then
        novaPagina;
    end;
    Report.ShowReport;
  finally
    Report.Free;
  end;
end;

Raylan Zibel

Raylan Zibel
Responder

Mais Posts

29/12/2015

Raylan Zibel

Resolvi essa parte com registros vazios no clientdataset.
Responder

26/04/2016

Raylan Zibel

Resolvido.
Responder

10/06/2016

Softsan Software

Boa Tarde Raylan, tudo bem?

Achei muito interessante a sua solução, porem não estou tendo sucesso em implementa-la, você poderia me passar no email como vc faz uso dessa rotina, como você faz para carregar o array e mandar para a rotina?

thiquintino@gmail.com

Desde já agradeço.
Responder

08/07/2016

Willian

teria como vc mandar o projeto?
notorionet@hotmail.com
Responder

08/07/2016

Raylan Zibel

Não entendi qual a duvida. É o processo de impressão de etiqueta normal. Mas pra começar de uma posição específica como eu precisava, coloquei registros vazios até chegar na posição que queria.
Responder

08/07/2016

Raylan Zibel

Fiz com array of array of string. Os primeiros registros vazios determinam a posição inicial para impressão.

//-----------------------------------------TABELA COM AS ETIQUETAS--------------------------------------------//  
type
  TEtiquetas = array of array of string;

//-----------------------------------------ROTINA DE IMPRESSÃO----------------------------------------------//  
procedure EtiquetaPimacoFast(Etiquetas: TEtiquetas);
{
uses DateUtils, frxClass, Math;
}
const
  TamFonte: Byte = 10;
  AlturaLinha: Byte = 15; // pixels // menor que 15 depende da fonte
  InchToPixel: Byte = 96; // 1 polegada
var
  x, y: Byte;
  i, j: Byte; 
  LinhaAtual: Byte;
  TotLinha, TotColuna: Byte;
  AlturaEtiqueta, LarguraEtiqueta: Double;
  MargemEsquerda, MargemDireita: Double;
  MargemSuperior, MargemInferior: Double;
  AlturaFolha, LarguraFolha: Double;
  Report: TfrxReport;
  Page: TfrxReportPage;
  Band: TfrxBand;
  Memo: TfrxMemoView;

  procedure novaPagina;
  begin
    // lendo ini // valores alternativos são de modelo A4->2x6 // valores em milímetros
    LarguraEtiqueta := (IniReadFlt('REPORT', 'LARGURA_ETIQUETA', 90.00));
    AlturaEtiqueta := (IniReadFlt('REPORT', 'ALTURA_ETIQUETA', 45.00));
    MargemSuperior := (IniReadFlt('REPORT', 'MARGEM_SUPERIOR', 10.00));
    MargemInferior := (IniReadFlt('REPORT', 'MARGEM_INFERIOR', 10.00));
    MargemEsquerda := (IniReadFlt('REPORT', 'MARGEM_ESQUERDA', 10.00));
    MargemDireita := (IniReadFlt('REPORT', 'MARGEM_DIREITA', 10.00));
    LarguraFolha := (IniReadFlt('REPORT', 'LARGURA_FOLHA', 210.00));
    AlturaFolha := (IniReadFlt('REPORT', 'ALTURA_FOLHA', 290.70));
    TotColuna := Floor(LarguraFolha - MargemEsquerda - MargemDireita) / LarguraEtiqueta);
    TotLinha := Floor((AlturaFolha - MargemSuperior - MargemInferior) / AlturaEtiqueta);
    // cria página
    Page := TfrxReportPage.Create(Report);
    Page.CreateUniqueName;
    Page.SetDefaults;
    // configura página
    Page.Width := LarguraFolha;
    Page.Height := AlturaFolha;
    Page.TopMargin := MargemSuperior;
    Page.BottomMargin := MargemInferior;
    Page.LeftMargin := MargemEsquerda;
    Page.RightMargin := MargemDireita;
    // converte pra pixels pra posicionar os MemoViews
    MargemEsquerda := MmToInch(MargemEsquerda) * InchToPixel;
    MargemSuperior := MmToInch(MargemSuperior) * InchToPixel;
    LarguraEtiqueta := MmToInch(LarguraEtiqueta) * InchToPixel;
    AlturaEtiqueta := MmToInch(AlturaEtiqueta) * InchToPixel;
    // cria banda na página
    Band := TfrxReportTitle.Create(Page);
    Band.CreateUniqueName;
    Band.Top := 0;
    Band.Height := Page.Height;
  end;

  procedure GravaMemo(Valor: string; Alinhamento: TfrxHAlign; Fonte: TFontStyles);
  begin
    // cria memo na banda da página
    Memo := TfrxMemoView.Create(Band);
    Memo.CreateUniqueName;
    // configura memo
    Memo.Text := Valor;
    Memo.Font.Size := TamFonte;
    Memo.Font.Style := Fonte;
    Memo.HAlign := Alinhamento;
    Memo.WordWrap := False;
    // memo é posicionado abaixo do memo anterior ((LinhaAtual - 1) * AlturaLinha)
    Inc(LinhaAtual);
    // primeira linha/coluna posiciona em margemesquerda/margemsuperior
    // demais linhas/colunas posicionam em margemesquerda+larguraetiqueta/margemsuperior+alturaetiqueta
    Memo.SetBounds(IfThen(j = 1, MargemEsquerda * j, MargemEsquerda + ((j - 1) * LarguraEtiqueta)), IfThen(i = 1, MargemSuperior + (i *
      LinhaAtual) + ((LinhaAtual - 1) * AlturaLinha), MargemSuperior + ((i - 1) * AlturaEtiqueta) + ((LinhaAtual - 1) * AlturaLinha)),
      LarguraEtiqueta, AlturaLinha);
  end;

begin
  try
    // cria report
    Report := TfrxReport.Create(Self);
    // configura preview do report
    with Report do
    begin
      Clear;
      PreviewOptions.ThumbnailVisible := True;
      PreviewOptions.ZoomMode := zmWholePage
    end;
    // pagina inicial
    novaPagina;
    x := 0;
    while x < Length(Etiquetas) do
    begin
      for i := 1 to TotLinha do
      begin
        if x = Length(Etiquetas) then
          Break;
        for j := 1 to TotColuna do
        begin
          if x = Length(Etiquetas) then
            Break;
          LinhaAtual := 0;
          for y := 0 to Length(Etiquetas[x]) - 1 do
          begin
            if y = 0 then // haCenter, fdBold
              GravaMemo(Etiquetas[x][y], haCenter, [fsBold])
            else // haLeft
              GravaMemo(Etiquetas[x][y], haLeft, []);
          end;
          Inc(x);
        end;
      end;
      Inc(x);
      // mais de uma página
      if x < Length(Etiquetas) then
        novaPagina;
    end;
    Report.ShowReport;
  finally
    Report.Free;
  end;
end;



Exemplo de uso do código acima.

procedure TForm1.btnTesteEtiquetaPimacoClick(Sender: TObject);
var
  i, pos: Byte;
  etiquetas: TEtiquetas;
begin
  SQLExecute('select nome, telefone, email from pessoas where (telefone is not null) and (email is not null)');
  SetLength(etiquetas, SQLCount);
  // posição cima pra baixo, esquerda pra direita, começa de 1
  pos := StrToIntDef(InputBox('Etiqueta', 'Posição Inicial da Etiqueta:', '1'), 1) - 1;
  if pos < 0 then
    Exit;
  // adiciona qtd de registros vazios antes da posição inicial
  SetLength(etiquetas, Length(etiquetas) + pos);
  for i := 1 to pos do
    SetLength(etiquetas[i-1], SQLFieldCount);
  // começa a alimentar a partir da posição inicial informada
  for i := pos to Length(etiquetas) - 1 do
  begin
    SetLength(etiquetas[i], SQLFieldCount);
    etiquetas[i][0] := 'TITULO DA ETIQUETA';
    etiquetas[i][1] := 'Nome:     ' + SQLFields('nome').AsString;
    etiquetas[i][2] := 'Telefone: ' + SQLFields('telefone').AsString;
    etiquetas[i][3] := 'Email:    ' + SQLFields('email').AsString;
    SQLNext;
  end;
  // executando preview
  EtiquetaPimacoFast(etiquetas);
end;
Responder

08/07/2016

Willian

boa tarde raylan
sou iniciante, se vc pudesse mandar os fontes desse exemplo ficaria grato.
notorionet@hotmail.com
Responder

08/07/2016

Raylan Zibel

boa tarde raylan
sou iniciante, se vc pudesse mandar os fontes desse exemplo ficaria grato.
notorionet@hotmail.com


Mas o fonte é só isso aí. Não tem form, não tem design. É gerado dinamicamente. Analise o código e entenda como foi feito.
Responder

08/07/2016

Willian

vc usou delphi 7
Responder

08/07/2016

Raylan Zibel

Sim.
Responder

11/07/2016

Willian

bom dia Raylan.
estou com um problema para declarar o IniReadFlt
Responder

11/07/2016

Raylan Zibel

É o mesmo que "ReadFloat".

function IniReadFlt(Chave, Variavel: string; Retorno: Double): Double;
begin
  with TIniFile.Create(DirExe + 'arquivo.ini') do
  try
    result := ReadFloat(Chave, Variavel, Retorno);
  finally
    Free;
  end;
end;
Responder

12/07/2016

Willian

bom dia
esta dando um erro nessa linha
TotColuna := Floor(LarguraFolha - MargemEsquerda - MargemDireita) / LarguraEtiqueta);

e nessa

MmToInch
Responder

12/07/2016

Raylan Zibel

uses Math;

function mmToInch(Mm: double): double;
begin
  Result := Mm / 25.4;
end;

Responder

12/07/2016

Willian

esta dando um erro nessa linha

TotColuna := Floor(LarguraFolha - MargemEsquerda - MargemDireita) / LarguraEtiqueta);

incompatilbe type: Byte and extended



como vc uso a funçao SQL
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

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

Aceitar