You are here

function theme_pdf_formatter_thumbnail in PDF 6

Same name and namespace in other branches
  1. 7 includes/pdf.field.inc \theme_pdf_formatter_thumbnail()

Formatter theme function for file fields : thumbnail

File

./pdf.module, line 95

Code

function theme_pdf_formatter_thumbnail($element) {
  if (isset($element['#item'])) {
    $file_url = file_create_url($element['#item']['filepath']);
  }
  drupal_add_js('sites/all/libraries/pdf.js' . '/build/pdf.js');
  $worker_loader = url('pdf/worker_loader.js');
  $js = "PDFJS.workerSrc = '{$worker_loader}';";
  $js .= "'use strict';\n  PDFJS.getDocument('{$file_url}').then(function(pdf) {\n    pdf.getPage(1).then(function(page) {\n      var scale = 1.5;\n      var viewport = page.getViewport(scale);\n      var canvas = document.getElementById('the-canvas');\n      var context = canvas.getContext('2d');\n      canvas.height = viewport.height;\n      canvas.width = viewport.width;\n      var renderContext = {\n        canvasContext: context,\n        viewport: viewport\n      };\n      page.render(renderContext);\n    });\n  });\n  ";
  drupal_add_js($js, 'inline', 'footer', FALSE, TRUE, FALSE);
  $output = '<canvas id="the-canvas" style="width:100%; border:1px solid black;"/>';
  return $output;
}