Reputation: 27648
What would be the simplest, shortest way to turn a text file into a PDF file with PHP? With some basic example code if possible.
I've seen this but the examples don't show how to use a text file as input.
https://www.php.net/manual/en/book.pdf.php
Thanks
Upvotes: 8
Views: 25174
Reputation: 56557
I wrote a smalll instruction:
1) download Full version(http://www.mpdf1.com/mpdf/index.php?page=Download ) and extract inside anyfolder
2) create sample.php
in anyfolder
and insert like this:
<?php
include('./mpdf.php');
$mpdf=new mPDF();
$mpdf->WriteHTML('<div style="color:yellow;">SAMPLE TEXT, WITH HTML TAGS Too!</div>');
$mpdf->Output(); die('');
?>
3) then open sample.php
in your browser to see the result!
MANY OTHER ONES - Convert HTML + CSS to PDF with PHP?
Upvotes: 0
Reputation: 317177
Throwing Zend_Pdf into the ring as well.
And a somewhat old tutorial to get you started in addition to the extensive docs in the ZF manual:
Upvotes: 1
Reputation: 1914
TCPDF and FPDF can both render PDF output. If you're on a Linux system, you could also call the system's ghostscript to do it.
Upvotes: 8
Reputation: 16094
TCPDF is the best way to convert text or HTML to PDF.
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
Upvotes: 2