public function download()
 {
     App::uses('CakePdf', 'Plugin/CakePdf/Pdf');
     $CakePdf = new CakePdf();
     $CakePdf->template('teste', 'default');
     $CakePdf->viewVars(array('nome' => 'Thiago'));
     $CakePdf->output();
     $path = WWW_ROOT . DS . 'files' . DS;
     $path .= uniqid() . '.pdf';
     if ($CakePdf->write($path)) {
         $this->response->file($path, array('download' => true, 'name' => 'teste_' . uniqid()));
         return $this->response;
     }
 }
 /**
  * Tests that the engine generates the right command
  *
  */
 public function testGetCommand()
 {
     $class = new ReflectionClass('WkHtmlToPdfEngine');
     $method = $class->getMethod('_getCommand');
     $method->setAccessible(true);
     $Pdf = new CakePdf(array('engine' => 'WkHtmlToPdf', 'title' => 'CakePdf rules', 'options' => array('quiet' => false, 'encoding' => 'ISO-8859-1')));
     $result = $method->invokeArgs($Pdf->engine(), array());
     $expected = "/usr/bin/wkhtmltopdf --print-media-type --orientation 'portrait' --page-size 'A4' --encoding 'ISO-8859-1' --title 'CakePdf rules' - -";
     $this->assertEquals($expected, $result);
     $Pdf = new CakePdf(array('engine' => 'WkHtmlToPdf', 'options' => array('boolean' => true, 'string' => 'value', 'integer' => 42)));
     $result = $method->invokeArgs($Pdf->engine(), array());
     $expected = "/usr/bin/wkhtmltopdf --quiet --print-media-type --orientation 'portrait' --page-size 'A4' --encoding 'UTF-8' --boolean --string 'value' --integer '42' - -";
     $this->assertEquals($expected, $result);
 }
 /**
  *
  * @dataProvider provider
  */
 public function testMargin($config)
 {
     $pdf = new CakePdf($config);
     $pdf->margin(15, 20, 25, 30);
     $expected = array('bottom' => 15, 'left' => 20, 'right' => 25, 'top' => 30);
     $this->assertEqual($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $pdf->margin(75);
     $expected = array('bottom' => 75, 'left' => 75, 'right' => 75, 'top' => 75);
     $this->assertEqual($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $pdf->margin(20, 50);
     $expected = array('bottom' => 20, 'left' => 50, 'right' => 50, 'top' => 20);
     $this->assertEqual($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $pdf->margin(array('left' => 120, 'right' => 30, 'top' => 34, 'bottom' => 15));
     $expected = array('bottom' => 15, 'left' => 120, 'right' => 30, 'top' => 34);
     $this->assertEqual($expected, $pdf->margin());
     $pdf = new CakePdf($config);
     $expected = array('bottom' => 15, 'left' => 50, 'right' => 30, 'top' => 45);
     $this->assertEqual($expected, $pdf->margin());
 }