Lançado Adianti Framework 7.6!
Clique aqui para saber mais
Espaçamento no relatório Boa tarde, prezados, estou desenvolvendo um formulário que gera um relatório, gostaria de saber se é possível colocar um espaçamento no relatório gerado em PDF? Estou gerando muitos dados e tão ficando colados ...
PA
Espaçamento no relatório  
Boa tarde, prezados, estou desenvolvendo um formulário que gera um relatório, gostaria de saber se é possível colocar um espaçamento no relatório gerado em PDF? Estou gerando muitos dados e tão ficando colados

  1. <?php
  2. class RelatorioMorador extends TPage
  3. {
  4.     private $form// form
  5.     private $user_unit_id;
  6.     
  7.     /**
  8.      * Class constructor
  9.      * Creates the page and the registration form
  10.      */
  11.     function __construct()
  12.     {
  13.         parent::__construct();
  14.         
  15.         // creates the form
  16.         $this->form = new BootstrapFormBuilder('form_Customer_report');
  17.         $this->form->setFormTitle('Relatório de moradores');
  18.         //pegar variável de sessão
  19.         $this->user_unit_id TSession::getValue('userunitid');
  20.         
  21.         // create the form fields
  22.         $nome = new TEntry('nome');
  23.         $this->form->addFields( [new TLabel('Apartamento/Casa')], [$nome] );
  24.         // define field properties
  25.         $nome->setSize'80%' );
  26.         $this->form->addAction'Gerar PDF', new TAction(array($this'onGenerate')), 'fa:file-pdf-o white')->class 'btn btn-sm btn-primary';
  27.         $this->form->addAction(('Limpar'),  new TAction(array($this'onClear')), 'fa:eraser text-white fa-lg')->class "btn btn-sm btn-info";
  28.         
  29.         // wrap the page content using vertical box
  30.         $vbox = new TVBox;
  31.         $vbox->style 'width: 100%';
  32.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  33.         $vbox->add($this->form);
  34.         
  35.         parent::add($vbox);
  36.     }
  37.     /**
  38.      * method onGenerate()
  39.      * Executed whenever the user clicks at the generate button
  40.      */
  41.     function onGenerate()
  42.     {
  43.         try
  44.         {
  45.             // open a transaction with database 'permission'
  46.             TTransaction::open('permission');
  47.             
  48.             // get the form data into an active record Pessoa
  49.             $data $this->form->getData();
  50.             $repository = new TRepository('Pessoa');
  51.             $criteria   = new TCriteria;
  52.             if ($data->nome)
  53.             {
  54.                 //criar filtro para buscar morador por apartamento
  55.                 $criteria->add(new TFilter('fk_id_dados_unidade''in'"(SELECT id FROM dados.dados_unidade WHERE nome ilike '%{$data->nome}%')"));
  56.             }
  57.             //Ordenação
  58.             $criteria->setProperty('order''nome');
  59.            
  60.             $customers $repository->load($criteria);
  61.             $format  'pdf';
  62.             
  63.             if ($customers)
  64.             {
  65.                 $widths = array(24016014000);
  66.                 //criar tabela PDF
  67.                 if($format){
  68.                     $table = new TTableWriterPDF($widths);
  69.                 }
  70.                 
  71.                 if (!empty($table))
  72.                 {
  73.                     // create the document styles
  74.                     $table->addStyle('title''Arial''10''',    '#ffffff''#607EFE');
  75.                     $table->addStyle('datap''Arial''10''',    '#000000''#E3E3E3''LR');
  76.                     $table->addStyle('datai''Arial''10''',    '#000000''#ffffff''LR');
  77.                     $table->addStyle('header''Times''16''BI''#000000''#CCCCCC');
  78.                     $table->addStyle('footer''Times''12''BI''#000000''#CCCCCC');
  79.                     
  80.                     $table->setHeaderCallback( function($table) {
  81.                         $table->addRow();
  82.                         
  83.                         //criar titulo 
  84.                         $estabelecimento = new SystemUnit($this->user_unit_id); //Pegar id da unidade e atribuir a variável
  85.                         $table->addCell('Lista de moradores - '.$estabelecimento->name'center''header'5);
  86.                         //criar titulo das colunas
  87.                         $table->addRow();
  88.                         $table->addCell('Moradores',        'left',   'title');
  89.                         $table->addCell('Telefone / Celular',         'center''title');
  90.                         $table->addCell('Apartamento/Casa''center''title');
  91.                     });
  92.                     
  93.                     $table->setFooterCallback( function($table) {
  94.                         $table->addRow();
  95.                         $table->addCell(date('d-m-Y H:i:s'), 'center''footer'5);
  96.                     });
  97.                     
  98.                     // controls the background filling
  99.                     $colour FALSE;
  100.                     
  101.                     // data rows
  102.                     foreach ($customers as $customer)
  103.                     {
  104.                         //Atribuir a variável apartamento os atributos do active record Unidade
  105.                         $apartamento = new Unidade($customer->fk_id_dados_unidade);
  106.                         //atribuir valores da variável as celulas da tabela
  107.                         if($apartamento->fk_id_system_unit == $this->user_unit_id){
  108.                             $style $colour 'datap' 'datai';
  109.                             $table->addRow();
  110.                             $table->addCell($customer->nome,     'left',   $style);
  111.                             // condições para atribuir valores as celulas da tabela
  112.                             if($customer->telefone && $customer->celular){
  113.                                 $table->addCell($customer->telefone.' / '.$customer->celular,   'center',   $style);
  114.                             } elseif (($customer->telefone == NULL) && ($customer->celular == NULL)) {
  115.                                 $table->addCell(' - ',   'center',   $style);
  116.                             } elseif ($customer->telefone == NULL) {
  117.                                 $table->addCell($customer->celular,   'center',   $style);
  118.                             } elseif($customer->celular == NULL){
  119.                                 $table->addCell($customer->telefone,   'center',   $style);
  120.                             }
  121.                             $table->addCell($apartamento->nome,  'center',   $style);
  122.                             
  123.                             $colour = !$colour;
  124.                         }
  125.                     }
  126.                     
  127.                     $output "app/output/tabular.{$format}";
  128.                     
  129.                     // stores the file
  130.                     if (!file_exists($output) OR is_writable($output))
  131.                     {
  132.                         $table->save($output);
  133.                         parent::openFile($output);
  134.                     }
  135.                     else
  136.                     {
  137.                         throw new Exception(_t('Permission denied') . ': ' $output);
  138.                     }
  139.                     
  140.                     // shows the success message
  141.                     new TMessage('info''Relatório gerado. Por favor, habilite os popups no navegador.');
  142.                 }
  143.             }
  144.             else
  145.             {
  146.                 new TMessage('error''Nenhum registro foi encontrado');
  147.             }
  148.     
  149.             // fill the form with the active record data
  150.             $this->form->setData($data);
  151.             
  152.             // close the transaction
  153.             TTransaction::close();
  154.         }
  155.         catch (Exception $e// in case of exception
  156.         {
  157.             // shows the exception error message
  158.             new TMessage('error'$e->getMessage());
  159.             
  160.             // undo all pending operations
  161.             TTransaction::rollback();
  162.         }
  163.     }
  164.     function onClear()
  165.     { 
  166.         // get the search form data
  167.         $data $this->form->getData();
  168.         $data->nome '';
  169.         
  170.         // fill the form with data again
  171.         $this->form->setData($data);
  172.     }   
  173. }   

Pacotão Dominando o Adianti Framework 7
O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado! Versão 7.4


Dominando o Adianti 7 Quero me inscrever agora!

Comentários (2)


NR

Entre as linhas? A TTableWriterPDF utiliza a FPDF para geração do relatório e você pode trabalhar diretamente com a instância da FPDF para fazer ajustes:
  1. <?php
  2. $fpdf $table->getNativeWriter();//retorna instancia da fpdf
  3. //$fpdf->setXY();
  4. //$fpdf->ln();
  5. ?>
PA

Muito obrigado Nataniel, sanou minha dúvida.