how to generate pdf and save to server

45,076

Solution 1

require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$content = $pdf->Output('doc.pdf','F');

http://www.fpdf.org/

Solution 2

You can use FPDF to generate pdf file....

http://www.fpdf.org/

This is simple and best way to generate pdf...

Solution 3

Use TCPDF to generate PDF file,

TCPDF Site: http://www.tcpdf.org/

Demo: http://www.tcpdf.org/examples.php

Share:
45,076

Related videos on Youtube

PHP Coder
Author by

PHP Coder

Updated on January 20, 2020

Comments

  • PHP Coder
    PHP Coder about 4 years

    Well, i'm trying to generate pdf file and save it to server but when i'm trying to view that pdf its showing invalid format.

    Code :

    <?php
    $content = "32w434";
    file_put_contents("xyz.pdf",$content);
    ?>
    

    If i change file from pdf to doc it works and opening perfectly but not pdf

    require('fpdf.php');
    
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Cell(40,10,'Hello World!');
    $content = $pdf->Output();
    file_put_contents("xyz.pdf",$content);
    

    That code giving output i don't want output on browser and still file is corrupted / invalid format

    • Cole Tobin
      Cole Tobin over 11 years
      That's because it doesn't save it as a PHP file. That's just text. Examine te file in a text editor next to a PDF in a text editor
    • PHP Coder
      PHP Coder over 11 years
      i'm not opening from ftp i'm directly opening it from link and also after downloading from cpanel
    • Cole Tobin
      Cole Tobin over 11 years
      It's not that it's corrupt download. Find out more on the PDF file format and instead use fpdf
    • Fernando Torres
      Fernando Torres almost 8 years
      I have the same question, is complicated but is possible.
  • PHP Coder
    PHP Coder over 11 years
    i try it but their documentation is too big i just want my html to be converted in pdf
  • Suresh kumar
    Suresh kumar over 11 years
    hey this is efficient way to create pdf file. You have to mention the co-ordinates only. if you try this u can do it in 30 mins. One question, whether data is dynamic or constant one?