0

I am working on a website where I have to generate PDF certificates, So far I am trying to add text and Image on the same page using FPDF in PHP, I am able to add a single image,but the moment I add a line of text some error pops in and Page goes blank. This page gives error. Error in the sense I get a blank page with no output Or pdf opened on it.

<?php
require('fpdf.php');
if(isset($_POST["Submit"]))
{
//create image from text
$text = $_POST["name"];
$pdf = new FPDF(); 
$pdf->AddPage();
$pdf->Image('head.jpg',0, 0, 210,100,'PNG');
$pdf->SetFont('Arial', '', 12);
$pdf->Text(105,68,"$text");
$pdf->Image('foot.jpg',0, 110, 210,100,'PNG');
$pdf->Output();
}
?>

But if I do this pdf is generated successfully with a image on it.

<?php
require('fpdf.php');
if(isset($_POST["Submit"]))
{
//create image from text
$text = $_POST["name"];
$pdf = new FPDF(); 
$pdf->AddPage();
$pdf->Image('head.jpg',0, 0, 210,100,'PNG');
//$pdf->SetFont('Arial', '', 12);
//$pdf->Text(105,68,"$text");
$pdf->Image('foot.jpg',0, 110, 210,100,'PNG');
$pdf->Output();
}
?>
Usman
  • 84
  • 8
  • 3
    Please state the error you're getting. Also, `'$text'` will not print the `$text` variable (not related to FPDF). – Jeto Nov 17 '19 at 19:45
  • `$pdf->Text(105,68,'$text');` should be `$pdf->Text(105,68,$text);` (without the single quotes). – M. Eriksson Nov 17 '19 at 19:47
  • Possible duplicate of [What is the difference between single-quoted and double-quoted strings in PHP?](https://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php) – M. Eriksson Nov 17 '19 at 19:49
  • 1
    @MagnusEriksson Definitely not what he wants but it's still a valid string though :) (I mean the FPDF error/blank page should not be related to that.) – Jeto Nov 17 '19 at 19:50
  • I was try and edit your code, just change "PNG" to "jpg" solve the problem. But I don't know why your second code is worked, your image type is "jpg", but you put "PNG". – Nur Muhammad Nov 18 '19 at 01:04

0 Answers0