0

I am trying shows pdf summary to user before download. There is pdf detail page to shows user pdf cover image, name, description, price, summary and buy now button.

Here's user wants to read summary of report then click on summary button and open model to read embed pdf. After read summary he wants to buy then will click on buy now button.

So, i want show only 2 pdf page on summary button. There is summary and buy now pdf report is same.

I tryed show summary of report, but there is show full pdf.

Here's my code below:-

public function raReportDetail($id){
$reportdetail = '';

$result = $this->connect()->query("SELECT * FROM wm_report WHERE id='$id'");
if($result->num_rows>0){
    $row=$result->fetch_assoc();

    $reportdetail ='            
        <div class="col-lg-4 col-md-4 col-sm-12">  
            <div class="large-5 column">
                <div class="xzoom-container">
                    <img class="img-fluid"  src="cover_images/'.$row['cover_img'].'">
                </div>        
            </div>
        </div>
        <div class="col-lg-8 col-md-8 col-sm-12">
            <div class="content-report-detail">
                <div class="large-12 column">
                    <h3>'.$row['name'].'</h3>
                </div>
                <hr>
                <div class="price-wrap">
                    <h3>Price: <i class="fa fa-rupee"></i> '.$row['price'].'/- </h3>
                </div>
                <div class="large-7 product-detail">
                    <p style="text-align: justify;">'.$row['description'].'</p>

                    <div class="ro-options">
                        <div class="no-row">
                            <div class="cart-btn-price">
                                <ul>
                                    <li>
                                        <a href="" data-toggle="modal" data-target="#Summary"> Summary </a> </li>
                                    <li>
                                        <a href="buy-report.php?id='.$row['id'].'"> Buy Now </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                        <div class="sku-code">
                            <span class="posted_in">Categary: '.$row['category'].'</span>
                            |
                            <span class="posted_in">SKU Code : '.$row['sku'].'</span>
                        </div>                    
                    </div>
                </div>
            </div>
        </div>

        <div id="Summary" class="modal fade" role="dialog">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 style="display: contents;">Summary of '.$row['name'].'</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <embed src="report/'.$row['report'].'" frameborder="0" width="100%" height="400px">
                    </div>
                </div>
            </div>    
        </div>
    ';
}else{
    $reportdetail = 'Something Went Wrong';
}

return $reportdetail;
}

2 Answers2

0

If you have the ImageMagick library installed in your PHP, you can convert a specific page to jpg.

$im = new Imagick();

$im->setResolution(300,300);
// the [0] below indicates the first page only.
$im->readImage('document.pdf[0]'); 
$im->setImageFormat('jpeg');    
$im->writeImage('thumb.jpg'); 
$im->clear(); 
$im->destroy();

You'd probably want to do this for the two pages you wanted to use as a preview.

See also the ImageMagick::readImage documents. The documentation itself isn't great, but the user comments are pretty good. You should be able to $im->setImageFormat('pdf'); as well.

I stole this from Convert PDF to JPEG with PHP and ImageMagick

PaulProgrammer
  • 16,175
  • 4
  • 39
  • 56
0

I would go with FPDI from setasign.

It is simple to use and easy to install. I currently use it in one of my application and it works very good.

https://www.setasign.com/products/fpdi/demos/simple-demo/

Bernhard
  • 1,852
  • 11
  • 19