Dompdf
This commit is contained in:
@@ -798,6 +798,10 @@ function update_status() {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Función para generar el PDF
|
||||
use Dompdf\Dompdf;
|
||||
use Dompdf\Options;
|
||||
|
||||
function pdf() {
|
||||
// Verificar que se recibió el ID
|
||||
if (!isset($_GET['id'])) {
|
||||
@@ -880,69 +884,29 @@ function pdf() {
|
||||
global $config;
|
||||
$nombre_sistema = $config['nombre_plataforma'] ?? 'Sistema Integral para Importadores de Hidrocarburos';
|
||||
$siglas = $config['siglas'] ?? 'SIIH';
|
||||
$logo_url = $config['logo_url'] ?? 'assets/img/logo_siih.png';
|
||||
$logo_path = realpath(__DIR__ . '/../../public/assets/img/logo_siih.png');
|
||||
$logo_url = 'file://' . $logo_path;
|
||||
|
||||
|
||||
// 5. Generar HTML del PDF
|
||||
$html = generarHTMLPDF($solicitud, $partidas, $nombre_sistema, $siglas, $logo_url);
|
||||
|
||||
// 6. Configurar headers para PDF
|
||||
// 6. Generar PDF usando DomPDF con Composer
|
||||
require_once __DIR__ . '/../../vendor/autoload.php'; // Ajusta ruta si es necesario
|
||||
|
||||
$options = new Options();
|
||||
$options->set('defaultFont', 'Arial');
|
||||
$options->set('isRemoteEnabled', true); // Permite cargar imágenes remotas si es necesario
|
||||
|
||||
$dompdf = new Dompdf($options);
|
||||
$dompdf->loadHtml($html);
|
||||
$dompdf->setPaper('A4', 'portrait');
|
||||
$dompdf->render();
|
||||
|
||||
// Enviar el PDF al navegador
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Disposition: inline; filename="solicitud_importacion_' . $id_solicitud . '.pdf"');
|
||||
|
||||
// 7. Generar PDF usando DomPDF
|
||||
// Opción 1: DomPDF v0.8.x (compatible con PHP 5.x)
|
||||
if (file_exists('lib/dompdf/dompdf-0.8.6/dompdf_config.inc.php')) {
|
||||
require_once 'lib/dompdf/dompdf-0.8.6/dompdf_config.inc.php';
|
||||
|
||||
$dompdf = new DOMPDF();
|
||||
$dompdf->load_html($html);
|
||||
$dompdf->set_paper('A4', 'portrait');
|
||||
$dompdf->render();
|
||||
|
||||
// Headers
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Disposition: inline; filename="solicitud_importacion_' . $id_solicitud . '.pdf"');
|
||||
|
||||
echo $dompdf->output();
|
||||
|
||||
// Opción 2: DomPDF v1.x/2.x (PHP 7+)
|
||||
} elseif (file_exists('vendor/autoload.php') && PHP_VERSION_ID >= 70000) {
|
||||
require_once 'vendor/autoload.php';
|
||||
|
||||
$options = new \Dompdf\Options();
|
||||
$options->set('defaultFont', 'Arial');
|
||||
$options->set('isRemoteEnabled', true);
|
||||
|
||||
$dompdf = new \Dompdf\Dompdf($options);
|
||||
$dompdf->loadHtml($html);
|
||||
$dompdf->setPaper('A4', 'portrait');
|
||||
$dompdf->render();
|
||||
|
||||
header('Content-Type: application/pdf');
|
||||
header('Content-Disposition: inline; filename="solicitud_importacion_' . $id_solicitud . '.pdf"');
|
||||
|
||||
echo $dompdf->output();
|
||||
|
||||
// Opción 3: Alternativa usando mPDF (compatible con PHP 5.6+)
|
||||
} elseif (file_exists('lib/mpdf/mpdf.php')) {
|
||||
require_once 'lib/mpdf/mpdf.php';
|
||||
|
||||
$mpdf = new mPDF();
|
||||
$mpdf->WriteHTML($html);
|
||||
$mpdf->Output('solicitud_importacion_' . $id_solicitud . '.pdf', 'I');
|
||||
|
||||
// Opción 4: TCPDF (muy compatible)
|
||||
} elseif (file_exists('lib/tcpdf/tcpdf.php')) {
|
||||
require_once 'lib/tcpdf/tcpdf.php';
|
||||
|
||||
$pdf = new TCPDF();
|
||||
$pdf->AddPage();
|
||||
$pdf->writeHTML($html, true, false, true, false, '');
|
||||
$pdf->Output('solicitud_importacion_' . $id_solicitud . '.pdf', 'I');
|
||||
|
||||
} else {
|
||||
throw new Exception("No hay librerías PDF disponibles. Instala DomPDF, mPDF o TCPDF.");
|
||||
}
|
||||
echo $dompdf->output();
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("Error generando PDF: " . $e->getMessage());
|
||||
@@ -1013,7 +977,7 @@ function generarHTMLPDF($solicitud, $partidas, $nombre_sistema, $siglas, $logo_u
|
||||
<!-- ENCABEZADO -->
|
||||
<div class="header">
|
||||
<div class="logo-section">
|
||||
<img src="' . htmlspecialchars($logo_url) . '" alt="Logo" class="logo">
|
||||
<img src="' . $logo_url . '" alt="Logo" class="logo">
|
||||
<div style="font-size: 8px; margin-top: 5px;">' . htmlspecialchars($siglas) . '</div>
|
||||
</div>
|
||||
|
||||
@@ -1050,7 +1014,7 @@ function generarHTMLPDF($solicitud, $partidas, $nombre_sistema, $siglas, $logo_u
|
||||
<div class="section-title">FECHA DE EXPEDICIÓN</div>
|
||||
<div class="text-center font-bold" style="font-size: 12px;">' . $fecha_expedicion . '</div>
|
||||
<div class="section-title" style="margin-top: 10px;">FECHA DE VENCIMIENTO</div>
|
||||
<div class="text-center">' . $fecha_vencimiento . '</div>
|
||||
<div class="text-center font-bold" style="font-size: 12px;">' . $fecha_vencimiento . '</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user