Skip to content

Commit

Permalink
Merge pull request #2 from vinimarcili/master
Browse files Browse the repository at this point in the history
Modulo de exportação de PDF com a biblioteca wkhtmltopdf
  • Loading branch information
vitorbarros authored Sep 15, 2016
2 parents e31db5f + d0952ab commit 965ef94
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
"psr-0": {
"VMBDataExport\\":"src/"
}
},
"require": {
"mikehaertl/phpwkhtmltopdf": "^2.2"
}
}
42 changes: 38 additions & 4 deletions src/VMBDataExport/Export/PDFExport.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace VMBDataExport\Export;

require __DIR__ .'/../../../vendor/autoload.php';
use Doctrine\ORM\EntityManager;
use mikehaertl\wkhtmlto\Pdf;

class PDFExport implements ExportDataServiceInterface
{
Expand All @@ -11,19 +12,50 @@ class PDFExport implements ExportDataServiceInterface
*/
private $em;

/**
* @var string
*/
private $path;

/**
* @var string
*/
private $html;

/**
* @var string
*/
private $link;

public function __construct(EntityManager $em)
{
$this->em = $em;
}

public function writeData(array $dados)
{
//TODO implement this action
}

public function export()
{
//TODO implement this action
$name = md5(rand(0, 999)) . '.pdf';
$path = __DIR__ . '/../../../../../../public/pdf/';
$pdf = new Pdf();

if ($this->link) {
$pdf->addPage($this->link);
}

if ($this->html) {
$pdf->addPage($this->html);
}

if ($this->path) {
$pdf->addPage($this->path);
}

$pdf->saveAs($path . $name);
return '/pdf/'.$name;
}

/**
Expand All @@ -33,6 +65,8 @@ public function export()
*/
public function writeCustomData(array $data, array $headers)
{
// TODO: Implement writeCustomData() method.
$this->link = isset($data['link']) ? $data['link'] : false;
$this->html = isset($data['html']) ? $data['html'] : false;
$this->path = isset($data['path']) ? $data['path'] : false;
}
}

0 comments on commit 965ef94

Please sign in to comment.