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
- <?php
- class RelatorioMorador extends TPage
- {
- private $form; // form
- private $user_unit_id;
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Customer_report');
- $this->form->setFormTitle('Relatório de moradores');
- //pegar variável de sessão
- $this->user_unit_id = TSession::getValue('userunitid');
- // create the form fields
- $nome = new TEntry('nome');
- $this->form->addFields( [new TLabel('Apartamento/Casa')], [$nome] );
- // define field properties
- $nome->setSize( '80%' );
- $this->form->addAction( 'Gerar PDF', new TAction(array($this, 'onGenerate')), 'fa:file-pdf-o white')->class = 'btn btn-sm btn-primary';
- $this->form->addAction(('Limpar'), new TAction(array($this, 'onClear')), 'fa:eraser text-white fa-lg')->class = "btn btn-sm btn-info";
- // wrap the page content using vertical box
- $vbox = new TVBox;
- $vbox->style = 'width: 100%';
- $vbox->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $vbox->add($this->form);
- parent::add($vbox);
- }
- /**
- * method onGenerate()
- * Executed whenever the user clicks at the generate button
- */
- function onGenerate()
- {
- try
- {
- // open a transaction with database 'permission'
- TTransaction::open('permission');
- // get the form data into an active record Pessoa
- $data = $this->form->getData();
- $repository = new TRepository('Pessoa');
- $criteria = new TCriteria;
- if ($data->nome)
- {
- //criar filtro para buscar morador por apartamento
- $criteria->add(new TFilter('fk_id_dados_unidade', 'in', "(SELECT id FROM dados.dados_unidade WHERE nome ilike '%{$data->nome}%')"));
- }
- //Ordenação
- $criteria->setProperty('order', 'nome');
- $customers = $repository->load($criteria);
- $format = 'pdf';
- if ($customers)
- {
- $widths = array(240, 160, 140, 0, 0);
- //criar tabela PDF
- if($format){
- $table = new TTableWriterPDF($widths);
- }
- if (!empty($table))
- {
- // create the document styles
- $table->addStyle('title', 'Arial', '10', '', '#ffffff', '#607EFE');
- $table->addStyle('datap', 'Arial', '10', '', '#000000', '#E3E3E3', 'LR');
- $table->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff', 'LR');
- $table->addStyle('header', 'Times', '16', 'BI', '#000000', '#CCCCCC');
- $table->addStyle('footer', 'Times', '12', 'BI', '#000000', '#CCCCCC');
- $table->setHeaderCallback( function($table) {
- $table->addRow();
- //criar titulo
- $estabelecimento = new SystemUnit($this->user_unit_id); //Pegar id da unidade e atribuir a variável
- $table->addCell('Lista de moradores - '.$estabelecimento->name, 'center', 'header', 5);
- //criar titulo das colunas
- $table->addRow();
- $table->addCell('Moradores', 'left', 'title');
- $table->addCell('Telefone / Celular', 'center', 'title');
- $table->addCell('Apartamento/Casa', 'center', 'title');
- });
- $table->setFooterCallback( function($table) {
- $table->addRow();
- $table->addCell(date('d-m-Y H:i:s'), 'center', 'footer', 5);
- });
- // controls the background filling
- $colour = FALSE;
- // data rows
- foreach ($customers as $customer)
- {
- //Atribuir a variável apartamento os atributos do active record Unidade
- $apartamento = new Unidade($customer->fk_id_dados_unidade);
- //atribuir valores da variável as celulas da tabela
- if($apartamento->fk_id_system_unit == $this->user_unit_id){
- $style = $colour ? 'datap' : 'datai';
- $table->addRow();
- $table->addCell($customer->nome, 'left', $style);
- // condições para atribuir valores as celulas da tabela
- if($customer->telefone && $customer->celular){
- $table->addCell($customer->telefone.' / '.$customer->celular, 'center', $style);
- } elseif (($customer->telefone == NULL) && ($customer->celular == NULL)) {
- $table->addCell(' - ', 'center', $style);
- } elseif ($customer->telefone == NULL) {
- $table->addCell($customer->celular, 'center', $style);
- } elseif($customer->celular == NULL){
- $table->addCell($customer->telefone, 'center', $style);
- }
- $table->addCell($apartamento->nome, 'center', $style);
- $colour = !$colour;
- }
- }
- $output = "app/output/tabular.{$format}";
- // stores the file
- if (!file_exists($output) OR is_writable($output))
- {
- $table->save($output);
- parent::openFile($output);
- }
- else
- {
- throw new Exception(_t('Permission denied') . ': ' . $output);
- }
- // shows the success message
- new TMessage('info', 'Relatório gerado. Por favor, habilite os popups no navegador.');
- }
- }
- else
- {
- new TMessage('error', 'Nenhum registro foi encontrado');
- }
- // fill the form with the active record data
- $this->form->setData($data);
- // close the transaction
- TTransaction::close();
- }
- catch (Exception $e) // in case of exception
- {
- // shows the exception error message
- new TMessage('error', $e->getMessage());
- // undo all pending operations
- TTransaction::rollback();
- }
- }
- function onClear()
- {
- // get the search form data
- $data = $this->form->getData();
- $data->nome = '';
- // fill the form with data again
- $this->form->setData($data);
- }
- }
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:
Muito obrigado Nataniel, sanou minha dúvida.