467,922 Members | 1,361 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,922 developers. It's quick & easy.

How do you write a php vairable to PDF using FPDF library?

32bit
I've tried using the following code to write a variable to a PDF file, but it only returns a blank PDF. How do you write a php variable to a library using the FPDF library?
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. session_start();
  3. require('../fpdf.php');
  4. if (isset ($_POST['sig'])) {
  5. $_POST['sig'] = $SESSION['sig'];
  6. $pdf = new FPDF();
  7. $pdf->AddPage();
  8. $pdf->SetFont('Arial','B',16);
  9. $_SESSION['sig'] = $sig;
  10. $pdf->Cell(40,10, $sig);
  11. $filename = '/var/www/html/foo/foo.pdf';
  12. $pdf-> Output($filename, 'F');
  13. }
  14. session_destroy();
  15. exit;
  16. ?>
  17. <!DOCTYPE html>
  18. <body>
  19. <br>&nbsp;<br>&nbsp;
  20. <form action="" method="post'>
  21. <label for "sig">Signature: </label>
  22. <input type="text" name="sig" placeholder="your signature here" id="sig" required>
  23. <br>&nbsp;<br>&nbsp;
  24. <input type="submit" value="Sign Document">
  25. </form>
  26. </body>
  27. </html>
  28.  
1 Week Ago #1

✓ answered by Niheel

You seem to sending a blank $sig in to the Cell method.

Change this:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['sig'] = $sig;
  2. $pdf->Cell(40,10, $sig);
to:
Expand|Select|Wrap|Line Numbers
  1. $sig = $_SESSION['sig'];
  2. $pdf->Cell(40,10, $sig);
  3.  
See if that works. :)

  • viewed: 1844
Share:
2 Replies
Niheel
Expert Mod 2GB
You seem to sending a blank $sig in to the Cell method.

Change this:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['sig'] = $sig;
  2. $pdf->Cell(40,10, $sig);
to:
Expand|Select|Wrap|Line Numbers
  1. $sig = $_SESSION['sig'];
  2. $pdf->Cell(40,10, $sig);
  3.  
See if that works. :)
1 Week Ago #2
32bit
@niheel
Yep, that was the problem. A simple oversight on setting the var.
1 Week Ago #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post: by
5 posts views Thread by cappieins | last post: by
reply views Thread by =?Utf-8?B?U2hyaWthbnQgTW9yZQ==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.