You are here

function print_pdf_generate_path in Printer, email and PDF versions 6

Same name and namespace in other branches
  1. 7.2 print_pdf/print_pdf.pages.inc \print_pdf_generate_path()
  2. 7 print_pdf/print_pdf.pages.inc \print_pdf_generate_path()
  3. 5.x print_pdf/print_pdf.pages.inc \print_pdf_generate_path()
1 call to print_pdf_generate_path()
print_pdf_controller in print_pdf/print_pdf.pages.inc
Generate a PDF version of the printer-friendly page

File

print_pdf/print_pdf.pages.inc, line 80

Code

function print_pdf_generate_path($path, $cid = NULL, $pdf_filename = NULL) {
  global $base_url;
  $print = print_controller($path, $cid, PRINT_PDF_FORMAT);
  if ($print === FALSE) {
    return;
  }

  // Img elements must be set to absolute
  $pattern = '!<(img\\s[^>]*?)>!is';
  $print['content'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['content']);
  $print['logo'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['logo']);
  $print['footer_message'] = preg_replace_callback($pattern, '_print_rewrite_urls', $print['footer_message']);

  // Send to printer option causes problems with PDF
  $print['sendtoprinter'] = '';
  $node = $print['node'];
  $html = theme('print_page', $print, PRINT_PDF_FORMAT, $node);
  $html = drupal_final_markup($html);

  // Convert the a href elements, to make sure no relative links remain
  $pattern = '!<(a\\s[^>]*?)>!is';
  $html = preg_replace_callback($pattern, '_print_rewrite_urls', $html);

  // And make anchor links relative again, to permit in-PDF navigation
  $html = preg_replace("!{$base_url}/" . PRINTPDF_PATH . '/.*?#!', '#', $html);
  return print_pdf_generate_html($print, $html, $pdf_filename);
}