<?php
session_start();
ob_start();
$user = $_SESSION["user_id"];
$myJPG = $_REQUEST['J'];
if (!isset($_SESSION["user_id"])) {
    header("location:../logout.php");
}
// $location = "../photo/insurance/"; 
$myJPG = "../photo/operationCard/".$myJPG;
?>
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>print</title>
    <link rel="stylesheet" href="css/print.css">
    <!-- <script src="../js/jquery.js"></script> -->
  </head>
  <body>
      <page size="A4">
        <div class="row">
        <script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
          <canvas id="the-canvas"></canvas>
        </div>
      </page>
      <script>
      var url = '<?php echo $myJPG ; ?>';

// Loaded via <script> tag, create shortcut to access PDF.js exports.
var pdfjsLib = window['pdfjs-dist/build/pdf'];

// The workerSrc property shall be specified.
pdfjsLib.GlobalWorkerOptions.workerSrc = '//mozilla.github.io/pdf.js/build/pdf.worker.js';

// Asynchronous download of PDF
var loadingTask = pdfjsLib.getDocument(url);
loadingTask.promise.then(function(pdf) {
  console.log('PDF loaded');
  
  // Fetch the first page
  var pageNumber = 1;
  pdf.getPage(pageNumber).then(function(page) {
    console.log('Page loaded');
    
    var scale = 1.36;
    var viewport = page.getViewport({scale: scale});

    // Prepare canvas using PDF page dimensions
    var canvas = document.getElementById('the-canvas');
    var context = canvas.getContext('2d');
    canvas.height = viewport.height;
    canvas.width = viewport.width;

    // Render PDF page into canvas context
    var renderContext = {
      canvasContext: context,
      viewport: viewport
    };
    var renderTask = page.render(renderContext);
    renderTask.promise.then(function () {
      console.log('Page rendered');
    });
  });
}, function (reason) {
  // PDF loading error
  console.error(reason);
});
      </script>
  </body>
</html>