1. Go to this page and download the library: Download asarmiento/laravel-fpdf library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asarmiento / laravel-fpdf example snippets
return [
'default_font' => 'Arial', // Fuente predeterminada
'default_size' => 12, // Tamaño de fuente predeterminado
'margin_left' => 10, // Margen izquierdo en mm
'margin_right' => 10, // Margen derecho en mm
'margin_top' => 10, // Margen superior en mm
'margin_bottom' => 10, // Margen inferior en mm
'orientation' => 'P', // Orientación: P (Portrait) o L (Landscape)
'unit' => 'mm', // Unidad de medida (mm, pt, cm, in)
'format' => 'A4' // Formato del papel
];
use Asarmiento\FriendlyFpdf\Facades\FriendlyFpdf;
public function generatePdf()
{
return FriendlyFpdf::addPage()
->addText('¡Hola Mundo!', 10, 10)
->Output('I', 'documento.pdf');
}
// Añadir una nueva página
FriendlyFpdf::addPage($orientation = '', $size = '', $rotation = 0);
// Añadir texto en una posición específica
FriendlyFpdf::addText($text, $x = null, $y = null, $align = 'L');
// Los valores válidos para $align son:
// 'L' - Alineación izquierda
// 'C' - Centrado
// 'R' - Alineación derecha
// Generar el PDF
FriendlyFpdf::Output($destination = 'I', $filename = 'doc.pdf');
// Valores para $destination:
// 'I' - Enviar al navegador
// 'D' - Forzar descarga
// 'F' - Guardar en archivo local
// 'S' - Retornar como string
use Asarmiento\FriendlyFpdf\Facades\FriendlyFpdf;
public function generateReport()
{
return FriendlyFpdf::addPage()
->addText('Reporte Mensual', 10, 10, 'C')
->addText('Fecha: ' . date('Y-m-d'), 10, 20)
->addText('Este es un ejemplo de reporte', 10, 30)
->Output('D', 'reporte.pdf');
}
FriendlyFpdf::addPage()
->addText('Contenido del PDF', 10, 10)
->Output('F', storage_path('app/pdfs/documento.pdf'));