diff --git a/composer.json b/composer.json index d9b524bf0b..065fd495a2 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,8 @@ }, "require": { "php": ">=5.4", - "stavarengo/php-sigep-fpdf": "dev-master" + "stavarengo/php-sigep-fpdf": "dev-master", + "setasign/fpdi": "1.6.1" }, "autoload": { "psr-0": { diff --git a/composer.lock b/composer.lock index 09b157201f..7cf4043cb0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,58 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "eca8c70728311b65159dfbe07ce7547b", - "content-hash": "7e4ee0b298a4f79cc6a990991324da44", + "hash": "b7aad08593280ed21f152ed41c8ced46", + "content-hash": "bf4c220f60e4bd834fc92f03692b7453", "packages": [ + { + "name": "setasign/fpdi", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/Setasign/FPDI.git", + "reference": "5b899b2b41463bf261aa69840fd30b50950a500c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Setasign/FPDI/zipball/5b899b2b41463bf261aa69840fd30b50950a500c", + "reference": "5b899b2b41463bf261aa69840fd30b50950a500c", + "shasum": "" + }, + "suggest": { + "setasign/fpdf": "FPDI will extend this class but as it is also possible to use \"tecnickcom/tcpdf\" as an alternative there's no fixed dependency configured.", + "setasign/fpdi-fpdf": "Use this package to automatically evaluate dependencies to FPDF.", + "setasign/fpdi-tcpdf": "Use this package to automatically evaluate dependencies to TCPDF." + }, + "type": "library", + "autoload": { + "classmap": [ + "filters/", + "fpdi.php", + "fpdf_tpl.php", + "fpdi_pdf_parser.php", + "pdf_context.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jan Slabon", + "email": "jan.slabon@setasign.com", + "homepage": "https://www.setasign.com" + } + ], + "description": "FPDI is a collection of PHP classes facilitating developers to read pages from existing PDF documents and use them as templates in FPDF. Because it is also possible to use FPDI with TCPDF, there are no fixed dependencies defined. Please see suggestions for packages which evaluates the dependencies automatically.", + "homepage": "https://www.setasign.com/fpdi", + "keywords": [ + "fpdf", + "fpdi", + "pdf" + ], + "time": "2015-11-30 10:53:14" + }, { "name": "stavarengo/php-sigep-fpdf", "version": "dev-master", @@ -50,7 +99,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": { - "php": ">=5.1.0" + "php": ">=5.4" }, "platform-dev": [] } diff --git a/exemplos/etiquetas.pdf b/exemplos/etiquetas.pdf new file mode 100644 index 0000000000..82622d82fe Binary files /dev/null and b/exemplos/etiquetas.pdf differ diff --git a/exemplos/helper-criar-pre-lista-a4.php b/exemplos/helper-criar-pre-lista-a4.php new file mode 100644 index 0000000000..8cc62d995f --- /dev/null +++ b/exemplos/helper-criar-pre-lista-a4.php @@ -0,0 +1,68 @@ +setAltura(20); + $dimensao->setLargura(20); + $dimensao->setComprimento(20); + $dimensao->setDiametro(0); + $dimensao->setTipo(\PhpSigep\Model\Dimensao::TIPO_PACOTE_CAIXA); + + $destinatario = new \PhpSigep\Model\Destinatario(); + $destinatario->setNome('Google Belo Horizonte'); + $destinatario->setLogradouro('Av. Bias Fortes'); + $destinatario->setNumero('382'); + $destinatario->setComplemento('6º andar'); + + $destino = new \PhpSigep\Model\DestinoNacional(); + $destino->setBairro('Lourdes'); + $destino->setCep('30170-010'); + $destino->setCidade('Belo Horizonte'); + $destino->setUf('MG'); + + // Estamos criando uma etique falsa, mas em um ambiente real voçê deve usar o método + // {@link \PhpSigep\Services\SoapClient\Real::solicitaEtiquetas() } para gerar o número das etiquetas + $etiqueta = new \PhpSigep\Model\Etiqueta(); + $etiqueta->setEtiquetaSemDv('PD73958096BR'); + + $servicoAdicional = new \PhpSigep\Model\ServicoAdicional(); + $servicoAdicional->setCodigoServicoAdicional(\PhpSigep\Model\ServicoAdicional::SERVICE_REGISTRO); + // Se não tiver valor declarado informar 0 (zero) + $servicoAdicional->setValorDeclarado(0); + + $encomenda = new \PhpSigep\Model\ObjetoPostal(); + $encomenda->setServicosAdicionais(array($servicoAdicional)); + $encomenda->setDestinatario($destinatario); + $encomenda->setDestino($destino); + $encomenda->setDimensao($dimensao); + $encomenda->setEtiqueta($etiqueta); + $encomenda->setPeso(0.500);// 500 gramas + $encomenda->setServicoDePostagem(new \PhpSigep\Model\ServicoDePostagem(\PhpSigep\Model\ServicoDePostagem::SERVICE_SEDEX_40096)); +// *** FIM DOS DADOS DA ENCOMENDA QUE SERÁ DESPACHADA *** // + +// *** DADOS DO REMETENTE *** // + $remetente = new \PhpSigep\Model\Remetente(); + $remetente->setNome('Google São Paulo'); + $remetente->setLogradouro('Av. Brigadeiro Faria Lima'); + $remetente->setNumero('3900'); + $remetente->setComplemento('5º andar'); + $remetente->setBairro('Itaim'); + $remetente->setCep('04538-132'); + $remetente->setUf('SP'); + $remetente->setCidade('São Paulo'); +// *** FIM DOS DADOS DO REMETENTE *** // + + +$plp = new \PhpSigep\Model\PreListaDePostagem(); +$plp->setAccessData(new \PhpSigep\Model\AccessDataHomologacao()); +$plp->setEncomendas([$encomenda,$encomenda,$encomenda,$encomenda]); +$plp->setRemetente($remetente); + +return $plp; diff --git a/exemplos/imprimirEtiquetas2016.php b/exemplos/imprimirEtiquetas2016.php index 90e40e9824..db6030e0e2 100644 --- a/exemplos/imprimirEtiquetas2016.php +++ b/exemplos/imprimirEtiquetas2016.php @@ -2,7 +2,7 @@ require_once __DIR__ . '/bootstrap-exemplos.php'; -$params = include __DIR__ . '/helper-criar-pre-lista.php'; +$params = include __DIR__ . '/helper-criar-pre-lista-a4.php'; // Logo da empresa remetente $logoFile = __DIR__ . '/logo-etiqueta-2016.png'; diff --git a/exemplos/imprimirEtiquetasA4.php b/exemplos/imprimirEtiquetasA4.php new file mode 100644 index 0000000000..1a4406d5f9 --- /dev/null +++ b/exemplos/imprimirEtiquetasA4.php @@ -0,0 +1,56 @@ +render('F',$fileName); + +unset($pdf); +$pdf = new \PhpSigep\PDF\ImprovedFPDF('P', 'mm', 'Letter' ); +$pageCount = $pdf->setSourceFile($fileName); + +$pdf->AddPage(); +$pdf->SetFillColor(0,0,0); +$pdf->SetFont('Arial','B',16); + +for($i=1;$i<=$pageCount;$i++) { + $tplIdx = $pdf->importPage($i, '/MediaBox'); + + $mod = $i % 4; + + switch ($mod) { + case 0: + //A4: 210(x) × 297(y) + //Letter: 216 (x) × 279 (y) + $pdf->useTemplate($tplIdx, 110, 145, 105, 138, true); + + if ($i !== $pageCount) { + $pdf->AddPage(); + $pdf->SetFillColor(0,0,0); + $pdf->SetFont('Arial','B',16); + } + break; + case 1: + $pdf->useTemplate($tplIdx, 10, 10, 105, 138, true); + break; + case 2: + $pdf->useTemplate($tplIdx, 110, 10, 105, 138, true); + break; + case 3: + $pdf->useTemplate($tplIdx, 10, 145, 105, 138, true); + break; + } + +} + + +$pdf->Output(); diff --git a/src/PhpSigep/Pdf/ImprovedFPDF.php b/src/PhpSigep/Pdf/ImprovedFPDF.php index 1b47f07c2e..4c5a618513 100755 --- a/src/PhpSigep/Pdf/ImprovedFPDF.php +++ b/src/PhpSigep/Pdf/ImprovedFPDF.php @@ -4,7 +4,7 @@ * @author: Stavarengo * @modify Anderson Luiz Silvério */ -class ImprovedFPDF extends \PhpSigepFPDF +class ImprovedFPDF extends \FPDI { /** * @var int @@ -21,7 +21,7 @@ class ImprovedFPDF extends \PhpSigepFPDF private $widths; private $aligns; - + function __construct($orientation = 'P', $unit = 'mm', $size = 'A4') { parent::__construct($orientation, $unit, $size); @@ -33,7 +33,7 @@ function __construct($orientation = 'P', $unit = 'mm', $size = 'A4') stream_wrapper_register("var", '\PhpSigep\Pdf\VariableStream') or die("Failed to register protocol"); //stream_wrapper_unregister("var"); } - + } public function _($str) @@ -210,7 +210,7 @@ function _putcatalog() { $this->_out('/Names <n_js).' 0 R>>'); } } - + function SetDash($black=null, $white=null) { if($black!==null) $s=sprintf('[%.3F %.3F] 0 d',$black*$this->k,$white*$this->k); @@ -218,19 +218,19 @@ function SetDash($black=null, $white=null) { $s='[] 0 d'; $this->_out($s); } - + function SetWidths($w) { //Set the array of column widths $this->widths=$w; } - + function SetAligns($a) { //Set the array of column alignments $this->aligns=$a; } - + function Row($data) { //Calculate the height of the row @@ -259,14 +259,14 @@ function Row($data) //Go to the next line $this->Ln($h); } - + function CheckPageBreak($h) { //If the height h would cause an overflow, add a new page immediately if($this->GetY()+$h>$this->PageBreakTrigger) $this->AddPage($this->CurOrientation); } - + function NbLines($w,$txt) { //Computes the number of lines a MultiCell of width w will take @@ -320,7 +320,7 @@ function NbLines($w,$txt) } return $nl; } - + function RoundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '') { $k = $this->k; @@ -333,7 +333,7 @@ function RoundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '') $op='S'; $MyArc = 4/3 * (sqrt(2) - 1); $this->_out(sprintf('%.2F %.2F m',($x+$r)*$k,($hp-$y)*$k )); - + $xc = $x+$w-$r; $yc = $y+$r; $this->_out(sprintf('%.2F %.2F l', $xc*$k,($hp-$y)*$k )); @@ -370,14 +370,14 @@ function RoundedRect($x, $y, $w, $h, $r, $corners = '1234', $style = '') $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r); $this->_out($op); } - + function _Arc($x1, $y1, $x2, $y2, $x3, $y3) { $h = $this->h; $this->_out(sprintf('%.2F %.2F %.2F %.2F %.2F %.2F c ', $x1*$this->k, ($h-$y1)*$this->k, $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k)); } - + } //Stream handler to read from global variables diff --git a/src/PhpSigep/Pdf/Semacode.php b/src/PhpSigep/Pdf/Semacode.php index 8464e0bd40..9828a45b28 100644 --- a/src/PhpSigep/Pdf/Semacode.php +++ b/src/PhpSigep/Pdf/Semacode.php @@ -45,7 +45,7 @@ class ReedSolomon { var $rslen = 0; - function ReedSolomon($blockSize) { + function __construct($blockSize) { // galois field polynomial for ECC 200 $this->initializeGaloisField(0x12d); // index is 1 for ECC 200 @@ -167,7 +167,7 @@ class Semacode { var $codings = "ACTXEB"; var $debug = false; - function Semacode() { + function __construct() { $this->Encodings = array( $this->makeEncoding(10, 10, 10, 10, 3, 3, 5), $this->makeEncoding(12, 12, 12, 12, 5, 5, 7),