You are here

function _print_pdf_file_access_images in Printer, email and PDF versions 5.4

Same name and namespace in other branches
  1. 6 print_pdf/print_pdf.pages.inc \_print_pdf_file_access_images()
  2. 7 print_pdf/print_pdf.pages.inc \_print_pdf_file_access_images()
  3. 5.x print_pdf/print_pdf.pages.inc \_print_pdf_file_access_images()

Convert image paths to the file:// protocol

In some Drupal setups, the use of the 'private' filesystem or Apache's configuration prevent access to the images of the page. This function tries to circumnvent those problems by accessing files in the local filesystem.

Parameters

$html: contents of the post-processed template already with the node data

See also

print_pdf_controller()

2 calls to _print_pdf_file_access_images()
_print_pdf_dompdf in print_pdf/print_pdf.pages.inc
Generate the PDF file using the dompdf library
_print_pdf_tcpdf in print_pdf/print_pdf.pages.inc
Generate the PDF file using the TCPDF library

File

print_pdf/print_pdf.pages.inc, line 107

Code

function _print_pdf_file_access_images($html) {
  global $base_url;

  // And converted from private to public paths
  $file_downloads = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC);
  if ($file_downloads == FILE_DOWNLOADS_PRIVATE) {
    $pattern = "!(<img\\s[^>]*?src\\s*?=\\s*?['\"]?){$base_url}/(?:(?:index.php)?\\?q=)?system/files/([^>]*?>)!is";
    $replacement = '$1file://' . realpath(file_directory_path()) . '/$2';
    $html = preg_replace($pattern, $replacement, $html);
  }
  $pattern = "!(<img\\s[^>]*?src\\s*?=\\s*?['\"]?){$base_url}/(?:(?:index.php)?\\?q=)?([^>]*?>)!is";
  $replacement = '$1file://' . dirname($_SERVER['SCRIPT_FILENAME']) . '/$2';
  $html = preg_replace($pattern, $replacement, $html);
  return $html;
}