Google trends Public Holidays Coupon Code Code Compiler

Create Thumbnails of an existing PDF document


Apr 28, 2019

In most of the website for some reasons we have a option to upload a PDF file and create preview thumbnails from uploaded PDF file. So in this tutorial I will explain you how to create a PDF preview image in PHP.

PHP code


function get($url)
{
    $ch = curl_init();
    $timeout = 5;
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}

$response = get('http://online.verypdf.com/api/?apikey=XXXX&app=pdftools&infile=http://www.orimi.com/pdf-test.pdf&outfile=IlRsD155ydOlvSGEEF91_18_db5d49df835c3589d4d7a94999492666_file.jpg&-f=1&-l=1&-width=298&-height=396');

$dr = explode(' ',$response);

$fileName1 = explode('/',str_replace("<br>","",$dr[1]));
// Get file name
$fileName = basename(end($fileName1));

$data = file_get_contents(str_replace("<br>","",$dr[1]));

// Upload thumbnails path
 $new = 't/'.$fileName;
 
 $upload =file_put_contents($new, $data);

Copyright 2024. All rights are reserved