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');
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
Related videos on Youtube
Author by
PHP Coder
Updated on January 20, 2020Comments
-
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 over 11 yearsThat'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 over 11 yearsi'm not opening from ftp i'm directly opening it from link and also after downloading from cpanel
-
Cole Tobin over 11 yearsIt's not that it's corrupt download. Find out more on the PDF file format and instead use fpdf
-
Fernando Torres almost 8 yearsI have the same question, is complicated but is possible.
-
-
PHP Coder over 11 yearsi try it but their documentation is too big i just want my html to be converted in pdf
-
Suresh kumar over 11 yearshey 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?