CN
Títulos e atributos em linhas excedem as larguras -relatórios
Código abaixo e, em anexo, o arquivo PDF gerado!
- <?php
- /**
- * EscalaReport Report
- * @author <your name here>
- */
- class EscalaReport extends TPage
- {
- protected $form; // form
- /**
- * Class constructor
- * Creates the page and the registration form
- */
- function __construct()
- {
- parent::__construct();
- // creates the form
- $this->form = new BootstrapFormBuilder('form_Escala_report');
- $this->form->setFormTitle('Escala de Serviço');
- // create the form fields
- $dt_lancamento = new TDate('dt_lancamento');
- $output_type = new TRadioGroup('output_type');
- // add the fields
- $this->form->addFields( [ new TLabel('DATA') ], [ $dt_lancamento ] );
- $this->form->addFields( [ new TLabel('Output') ], [ $output_type ] );
- $output_type->addValidation('Output', new TRequiredValidator);
- // set sizes
- $dt_lancamento->setSize('100%');
- $output_type->setSize('100%');
- $output_type->addItems(array('html'=>'HTML', 'pdf'=>'PDF', 'rtf'=>'RTF', 'xls' => 'XLS'));
- $output_type->setLayout('horizontal');
- $output_type->setUseButton();
- $output_type->setValue('pdf');
- $output_type->setSize(70);
- // add the action button
- $btn = $this->form->addAction(_t('Generate'), new TAction(array($this, 'onGenerate')), 'fa:cog');
- $btn->class = 'btn btn-sm btn-primary';
- // vertical box container
- $container = new TVBox;
- $container->style = 'width: 90%';
- // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
- $container->add($this->form);
- parent::add($container);
- }
- /**
- * Generate the report
- */
- function onGenerate()
- {
- try
- {
- // open a transaction with database 'ortotrauma'
- TTransaction::open('ortotrauma');
- // get the form data into an active record
- $data = $this->form->getData();
- $this->form->validate();
- $repository = new TRepository('Escala');
- $criteria = new TCriteria;
- if ($data->dt_lancamento)
- {
- $criteria->add(new TFilter('dt_lancamento', '>=', "%{$data->dt_lancamento}%"));
- }
- $objects = $repository->load($criteria, FALSE);
- $format = $data->output_type;
- if ($objects)
- {
- $widths = array(100,100,100,100,100,100,100,100);
- switch ($format)
- {
- case 'html':
- $tr = new TTableWriterHTML($widths);
- break;
- case 'pdf':
- $tr = new TTableWriterPDF($widths);
- break;
- case 'xls':
- $tr = new TTableWriterXLS($widths);
- break;
- case 'rtf':
- $tr = new TTableWriterRTF($widths);
- break;
- }
- // create the document styles
- $tr->addStyle('title', 'Arial', '10', 'B', '#ffffff', '#A3A3A3', 'LR');
- $tr->addStyle('datap', 'Arial', '10', '', '#000000', '#EEEEEE', 'LR');
- $tr->addStyle('datai', 'Arial', '10', '', '#000000', '#ffffff', 'LR');
- $tr->addStyle('header', 'Arial', '12', '', '#ffffff', '#6B6B6B', 'LR');
- $tr->addStyle('footer', 'Times', '10', 'I', '#000000', '#A3A3A3', 'LR');
- // add a header row
- $tr->addRow();
- $tr->addCell('ESCALA DE SERVIÇO', 'center', 'header', 8);
- // add titles row
- $tr->addRow();
- $tr->addCell('DATA', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 1', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 2', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 3', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 4', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 5', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 6', 'center', 'title');
- $tr->addCell('NOME DO SERVIÇO 7', 'center', 'title');
- // controls the background filling
- $colour= FALSE;
- // data rows
- foreach ($objects as $object)
- {
- $style = $colour ? 'datap' : 'datai';
- $tr->addRow();
- $tr->addCell($object->dt_lancamento, 'center', $style);
- $tr->addCell($object->Medico_Coluna1->nome, 'center', $style);
- $tr->addCell($object->Medico_Coluna2->nome, 'center', $style);
- $tr->addCell($object->Medico_Coluna3->nome, 'center', $style);
- $tr->addCell($object->Medico_Coluna4->nome, 'center', $style);
- $tr->addCell($object->Medico_Coluna5->nome, 'center', $style);
- $tr->addCell($object->Medico_Coluna6->nome, 'center', $style);
- $tr->addCell($object->Medico_Coluna7->nome, 'center', $style);
- $colour = !$colour;
- }
- // footer row
- $tr->addRow();
- $tr->addCell(date('Y-m-d h:i:s'), 'center', 'footer', 8);
- // stores the file
- if (!file_exists("app/output/Escala.{$format}") OR is_writable("app/output/Escala.{$format}"))
- {
- $tr->save("app/output/Escala.{$format}");
- }
- else
- {
- throw new Exception(_t('Permission denied') . ': ' . "app/output/Escala.{$format}");
- }
- // open the report file
- parent::openFile("app/output/Escala.{$format}");
- // shows the success message
- new TMessage('info', 'Report generated. Please, enable popups.');
- }
- else
- {
- new TMessage('error', 'No records found');
- }
- // 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();
- }
- }
- }
Você pode imprimir como paisagem, basta passar "L" no segundo parâmetro do construtor da classe TTableWriterPDF. Veja a assinatura do construtor:
Testei, porém, ainda esta cortanto o título. Tem como quebrar somente o título, como se fosse numa planilha no excel?
Ex.
Total de
Dias
A TTableWriterPdf não tem esse recurso. Se não for possível diminuir a fonte ou aumentar o tamanho dessa coluna você precisa trabalhar diretamente com a FPDF ou Dompdf, por exemplo.