You are here

function theme_pdf_formatter_pages in PDF 7

1 theme call to theme_pdf_formatter_pages()
pdf_field_formatter_view in includes/pdf.field.inc
Implements hook_field_formatter_view().

File

includes/pdf.field.inc, line 265

Code

function theme_pdf_formatter_pages($variables) {
  $scale = $variables['scale'];
  $module_path = drupal_get_path('module', 'pdf');
  if (isset($variables['file']->uri)) {
    $file_url = file_create_url($variables['file']->uri);
    $filename = $variables['file']->filename;
    $fid = $variables['file']->fid;
  }
  elseif (isset($variables['file']->url)) {
    $file_url = $variables['file']->url;
    $filename = end(explode('/', $variables['file']->url));
    $fid = $filename;
  }
  drupal_add_css($module_path . '/css/TextLayer.css');
  drupal_add_css($module_path . '/css/pdf.css');
  $library = libraries_load('pdf.js', 'viewer');
  if ($library['loaded'] == FALSE) {
    drupal_set_message($library['error message'], 'error');
    return 'Please download and install ' . l($library['name'], $library['download url']) . '!';
  }
  $worker_loader = file_create_url(libraries_get_path('pdf.js') . '/build/pdf.worker.js') . "?v={$library['version']}";
  if (version_compare(2, $library['version']) == 1) {
    $js = "PDFJS.workerSrc = '{$worker_loader}';";
  }
  else {
    $js = "pdfjsLib.workerSrc = '{$worker_loader}';";
  }
  drupal_add_js($js, array(
    'type' => 'inline',
  ));

  // drupal_add_js($module_path . '/js/pdf.js');.
  $link = array(
    'text' => $filename,
    'path' => $file_url,
    'options' => array(
      'attributes' => array(),
      'html' => FALSE,
    ),
  );
  $html = array(
    '#type' => 'html_tag',
    '#tag' => 'div',
    '#value' => t('Download: ') . theme_link($link),
    '#attributes' => array(
      'class' => array(
        'pdf-pages',
      ),
      'id' => array(
        'viewer',
        'fid-' . $fid,
      ),
      'scale' => $variables['scale'],
      'file' => $file_url,
    ),
  );
  $html['#attached']['js'] = array(
    $module_path . '/js/pdf.js',
  );
  $html['#attached']['css'] = array(
    $module_path . '/css/pdf.css',
  );
  return render($html);
}