I am developing a website for a charity, in which a user gets a receipt generated after making a donation.
My client wants the user to be able save this receipt as an image or pdf.
I have tried many API's and plugins, and even had my server admin install phantom.js, but I am unfamiliar with phantom, and couldn't get it to work.
Any help would be greatly appreciated.
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
You can use FPDF php library to achieve this . FPDF is a free , php class which provide high level function and support many features like :
Image Support(Jpeg,png)
Color
Links,
Automatic page break and many more
click here for quick tutorial.
Demo Code
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Don't forget to include fpdf.php
Related
I have a simple app where the php file updates the database then it generates a pdf file and stores in local folder. below is the code. the pdf file is getting generated and working fine. but am not able to add text into it. when i insert image its working. but inserting cell or text is not working. i dont know whats gone wrong.. pl;z help me.. thanks
$pdf = new FPDF();
$pdf->AddPage();
// $pdf->Image('images/logo.png',90,15,90,0,'PNG');
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("pdffiles/testsuccess.pdf",'F');
When I test your code it works fine for me. The only thing I DON'T see in your code is the require statement for the fpdf.php file.
heres the FULL php file contents for the example that works for me:
<?php
require('fpdf/fpdf.php'); // MAKE SURE YOU HAVE THIS LINE
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output("testsuccess.pdf",'F');
?>
Finally, I found it.. weird but it will be very useful for the developers who is new to fpdf... I have mentioned that image is working and only text is not working.. Means you should include the fonts folder which comes with fpdf when downloading. If fonts folder is missing it does not print any text..
Thank you
I'm trying to work with FPDF to export Data from a HTML-Form to a PDF and can't get it to work. I tried the example given in the downloadable tutorial and got only a part of the code back instead of an actual error or even a PDF.
This is the example I used
<?php
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
And the output looks like this:
AddPage(); $pdf->SetFont('Arial','B',16); $pdf->Cell(40,10,'Hello World!'); $pdf->Output(); ?>
I did it exactly as any youtube-tutorials shows it. The file fpdf.php is in the same folder as my php-code and so on. I just don't see what I'm doing wrong.
I have a requirement where two pdfs need to be created at once. A for loop will not work as one file is going to be a certificate pdf. The next file is going to be an Invoice pdf. I know I am missing something simple or else its not possible to do this. I have attached a simple code to demonstrate what I mean. The files are executed on a form submission.I have made two files and then a handler file to include the two files but still only outputs on pdf.
<?php
require('fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Im a certificate');
$pdf->Output('Certificate.pdf', 'D'); //Output of the first invoice
$pdf = new FPDF(); // This is going to be the second pdf the Invoice
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Im an invoice');
$pdf->Output('This is a invoice.pdf', 'D');
//The problem is it only outputs the first one not this one
?>
I have a php page that creates a pdf file and output its on browser.
I want my php page to upload it on a webserver (cPanel). i've found lots of sites explaining how to upload file througt form and file type but i can't do this. Anyone knows how to?
You can use fpdf to do this easily.
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');
This will save the pdf with content Hello World as its content in the public_html directory of your webserver.
Or you could use
file_put_contents("fileName.pdf", fopen("http://your.url.com/file.pdf", 'r'));
i have a big problem with fpdf
in my page i have a lot of code and at the end i create a pdf file with this sample:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
ob_end_clean();
$pdf->Output();
the result is that only the creatioin of pdf are make and the other code no !
first the code of the sample is:
require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
//ob_end_clean();
$pdf->Output();
like this the code before is execute without problem but not the pdf and i receive this on browser:
FPDF error: Some data has already been output, can't send PDF file
can you help me ?
im newbie with fpdf libraries
that is because your php code has already outputted some data to the browser.
Check that your php do not write any data to the browser yet ( except for the headers ) before calling $pdf->Output(), thus avoiding sending unknown data that has a pdf binary data appended at the end.
the ob_end_clean() function call ensure that your script clean any previous output your php script could have made.