Webmaster Blog

Members blog at WebmaisterPro. Covering topics related to online marketing, SEO, web development as well as software reviews.

PHP Useful Snippets To Convert PDF, TXT, HTML and Images

Recently worked on project that required few different file type conversions. To be honest, I had to brush my PHP a bit, but thanks to Internet I was able to discover these useful snippets that saved me tons of time. Convert PDF to JPG images - PDF2JPG This require Image Magic extension installed. Simple and very useful snippet that conver .PDF files in to image files .jpg format. /** * PDF2JPG script * with ImageMagick */ $pdf_file = './pdf/_folder/example.pdf'; $save_to = './image_folder/example.jpg'; //make sure that apache has permissions to write in this folder! (common problem) //execute ImageMagick command 'convert' and convert PDF to JPG with applied settings exec('convert "'.$pdf_file.'" -colorspace RGB -resize 800 "'.$save_to.'"', $output, $return_var); if($return_var == 0) { //if exec successfuly converted pdf to jpg print "Conversion OK"; } else print "Conversion failed.<br />".$output;     html2ps - convert HTML to pdf This is definitely very useful snippets, that convert HTML to PDF file. I have use it in few projects. /******************************************************************************* * */ function convert_to_pdf($url, $path_to_pdf) { require_once(dirname(__FILE__).'/html2ps/config.inc.php'); require_once(HTML2PS_DIR.'pipeline.factory.class.php'); echo WRITER_TEMPDIR; //error_reporting(E_ALL); //ini_set("display_errors","1"); @set_time_limit(10000); parse_config_file(HTML2PS_DIR.'html2ps.config'); /** * Handles the saving of generated PDF to user-defined output file on server */ class MyDestinationFile extends Destination { /** * @var String...
Rate this blog entry:
Continue reading
15509 Hits