require_once 'vendor/autoload.php'; use Dompdf\Dompdf; $dompdf = new Dompdf(); $html = 'Hello, World!'; $dompdf->loadHtml($html); $dompdf->render(); $dompdf->stream(); // Output the generated PDF to browser
require_once('tcpdf/tcpdf.php'); $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('John Doe'); $pdf->SetSubject('Example PDF'); $pdf->SetKeywords('TCPDF, PDF, example'); $pdf->AddPage(); $pdf->SetFont('times', '', 12); $pdf->Cell(0, 10, 'Hello, World!', 0, false, 'C', 0); $pdf->Output(); // Output the PDF to browser
require('fpdf/fpdf.php'); $pdf = new FPDF(); $pdf->AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello, World!'); $pdf->Image('path/to/image.jpg', 10, 50, 50, 50, 'JPG'); $pdf->Output(); // Output the PDF to browserIn conclusion, the above examples demonstrate the use of different PHP PDF libraries, such as 'Dompdf', 'TCPDF', and 'FPDF'. Developers can choose the most suitable library based on their requirements and preferences.