You are here

function theme_pdf_js in PDF Reader 7.2

1 theme call to theme_pdf_js()
theme_pdf_reader in ./pdf_reader.module
Theme the field with pdf reader

File

./pdf_reader.module, line 307
pdf reader module file.

Code

function theme_pdf_js($variables) {
  $library = libraries_load('pdf.js');
  if ($library['loaded'] == FALSE) {
    drupal_set_message($library['error message'], 'error');
    return 'Please download and install ' . l($library['name'], $library['download url']) . '!';
  }
  $file_url = isset($variables['file']['uri']) ? file_create_url($variables['file']['uri']) : $variables['file']['value'];
  $library_path = libraries_get_path('pdf.js');
  $iframe_src = file_create_url($library_path . '/web/viewer.html') . '?file=' . rawurlencode($file_url);
  $html = array(
    '#type' => 'html_tag',
    '#tag' => 'iframe',
    '#value' => $file_url,
    '#attributes' => array(
      'class' => array(
        'pdf-reader',
      ),
      'webkitallowfullscreen' => '',
      'mozallowfullscreen' => '',
      'allowfullscreen' => '',
      'frameborder' => 'no',
      'width' => $variables['settings']['pdf_width'],
      'height' => $variables['settings']['pdf_height'],
      'src' => $iframe_src,
      'data-src' => $file_url,
    ),
  );
  return render($html);
}