Skip to content

Commit

Permalink
Añadido soporte unicode a los nuevos PDF.
Browse files Browse the repository at this point in the history
  • Loading branch information
NeoRazorX committed Nov 11, 2023
1 parent 535881c commit d33f022
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
23 changes: 15 additions & 8 deletions Core/Lib/Export/PDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
use FacturaScripts\Core\Template\PdfEngine;
use FacturaScripts\Core\Tools;
use FacturaScripts\Dinamic\Model\AttachedFile;
use FPDF;
use tFPDF;

class PDF extends PdfEngine
{
Expand All @@ -39,7 +39,7 @@ class PDF extends PdfEngine
protected $file_name;

/** @var string */
protected $font_family = 'Arial';
protected $font_family = 'DejaVuSans';

/** @var int */
protected $font_size = 10;
Expand All @@ -50,7 +50,7 @@ class PDF extends PdfEngine
/** @var string */
protected $orientation;

/** @var FPDF */
/** @var tFPDF */
protected $pdf;

/** @var bool */
Expand Down Expand Up @@ -212,13 +212,13 @@ public function addTable(array $rows, array $header = [], array $options = []):
$anchoColumna = $anchoPagina / count($header);

// Crea la tabla
$this->pdf->SetFont($this->font_family, 'B', 12);
$this->pdf->SetFont($this->font_family, 'B', 11);
$this->pdf->SetFillColor(150, 150, 150); // Establece el color de fondo de las celdas de la cabecera
$this->pdf->SetTextColor(255); // Establece el color del texto de la cabecera

// Imprime las cabeceras con el ancho ajustado
foreach ($header as $cabecera) {
$this->pdf->Cell($anchoColumna, 10, $cabecera, 1, 0, 'C', 1);
$this->pdf->Cell($anchoColumna, 15, $cabecera, 1, 0, 'C', 1);
}

$this->pdf->Ln(); // Salta a la siguiente línea
Expand All @@ -231,7 +231,7 @@ public function addTable(array $rows, array $header = [], array $options = []):
// Imprime las filas con el ancho ajustado
foreach ($rows as $fila) {
foreach ($fila as $columna) {
$this->pdf->Cell($anchoColumna, 10, $columna, 1);
$this->pdf->Cell($anchoColumna, 15, $columna, 1);
}
$this->pdf->Ln(); // Salta a la siguiente línea
}
Expand Down Expand Up @@ -259,7 +259,7 @@ public function addText(string $text, array $options = []): self
// cambiamos el tamaño de la fuente
$this->pdf->SetFont($this->font_family, $options['font-weight'], $options['font-size']);

$this->pdf->cell(0, $options['font-size'] + 5, $text, 0, 1, $options['align']);
$this->pdf->MultiCell(0, $options['font-size'] + 5, $text, 0, $options['align']);

// volvemos al tamaño de fuente por defecto
$this->pdf->SetFont($this->font_family, $this->font_weight, $this->font_size);
Expand All @@ -279,11 +279,18 @@ public function newPage(): self
}

if (null === $this->pdf) {
$this->pdf = new FPDF($this->orientation, 'pt', $this->size);
$this->pdf = new tFPDF($this->orientation, 'pt', $this->size);
$this->pdf->SetTitle($this->title);
$this->pdf->SetAuthor(Session::user()->nick);
$this->pdf->SetCreator('FacturaScripts');

// añadimos las fuentes
$this->pdf->AddFont($this->font_family, '', 'DejaVuSans.ttf', true);
$this->pdf->AddFont($this->font_family, 'B', 'DejaVuSans-Bold.ttf', true);

// establece la fuente por defecto
$this->pdf->SetFont($this->font_family, $this->font_weight, $this->font_size);

$this->pdf->AddPage();
return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"ext-bcmath": "*",
"ext-gd": "*",
"ext-curl": "*",
"setasign/fpdf": "^1.8"
"setasign/tfpdf": "^1.33"
},
"require-dev": {
"phpunit/phpunit": "8.*",
Expand Down

0 comments on commit d33f022

Please sign in to comment.