You are here

function theme_pdf_formatter_default in PDF 7

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

File

includes/pdf.field.inc, line 173

Code

function theme_pdf_formatter_default($variables) {
  $library = libraries_detect('pdf.js');
  if ($library['installed'] == FALSE) {
    drupal_set_message($library['error message'], 'error');
    return 'Please download and install ' . l($library['name'], $library['download url']) . '!';
  }
  if (isset($variables['file']->uri)) {
    $file_url = file_create_url($variables['file']->uri);
  }
  elseif (isset($variables['file']->url)) {
    $file_url = $variables['file']->url;
  }
  $module_path = drupal_get_path('module', 'pdf');
  $library_path = libraries_get_path('pdf.js', 'viewer');
  $iframe_src = file_create_url($library_path . '/web/viewer.html') . '?file=' . rawurlencode($file_url);
  $force_pdfjs = $variables['keep_pdfjs'];
  $html = array(
    '#type' => 'html_tag',
    '#tag' => 'iframe',
    '#value' => $file_url,
    '#attributes' => array(
      'class' => array(
        'pdf',
      ),
      'webkitallowfullscreen' => '',
      'mozallowfullscreen' => '',
      'allowfullscreen' => '',
      'frameborder' => 'no',
      'width' => $variables['width'],
      'height' => $variables['height'],
      'src' => $iframe_src,
      'data-src' => $file_url,
    ),
  );
  if ($force_pdfjs != TRUE) {
    drupal_add_js($module_path . '/js/acrobat_detection.js');
    drupal_add_js($module_path . '/js/default.js');
  }
  return render($html);
}