Since this question has been asked a long time ago, I think I need to help with my experience before.
Answer: you cannot
Why? because PDF is issued by external applications such as Adobe PDF Reader, foxit or more. And you cannot attach an event to them.
if you are using adobe reader. The only thing you can do is go to the page, zoom, etc. The full example can be read here: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf#page=8 (see I will bring you directly to page 8 on the first page )
But, hei .. how if our client uses other applications? we will be more embarrassed
The way to do this is to create your own PDF viewer.
we can use the js library, for example: http://www.bestjquery.com/2012/09/best-jquery-pdf-viewer-plugin-examples/
but here I will show you to use pdf.js , which was created by mozilla.
main.php
<style> .preview{ display:none; width: 400px; height: 400px; border: 1px solid black; } </style> <a href="pdfreader.php?pdfxs=test.pdf" style="color:#999;" id="nextpdf">file/test.pdf</a><br> <a href="pdfreader.php?pdfxs=test1.pdf" style="color:#999;" id="nextpdf">file/test1.pdf</a><br> <div class="preview"> <iframe id="myiframe" frameborder="0" width="400px" height="400px" >not support iframe</iframe> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $(document).on('click', '#nextpdf', function(e){ e.preventDefault(); $('#myiframe').attr('src', $(this).attr('href')); $('.preview').show(); }); </script>
pdfreader.php
<?php $path = 'file/'; $pdf = isset($_GET['pdfxs']) ? $path . $_GET['pdfxs'] : ''; if(!file_exists($pdf) || !mime_content_type($pdf) =='application/pdf') die('file not found'); ?> <div id="pdf-container"> <div id="pdf-box"></div> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="//mozilla.imtqy.com/pdf.js/build/pdf.js"></script> <script> $(function(){ </script>
Note: I put pdf in the file/ folder
in main.php you will notice that you can attach the event scroll (and click too) in pdf. because our PDF is no longer displayed by external applications.
and the last part - if you carefully read pdfreader.php , you will notice that you no longer need an iframe . You just need a div, and then you can fully handle all the events that you want to use in your pdf format: for example, scrolling, clicking, changing a page, scaling, etc. Why? because now your pdf file is now replaced with a canvas (pdf.js makes your pdf document as an HTML5 canvas). see full example pdf.js