Hi there.

Does any of you know how to get the current panel page entire html (styled and ready), in code. - With drupal_http_request i get a 403 forbidden. Is there any other way.

I need the html for rendering in the pdf_using_mpdf_api()-function.

Any ideas?

Comments

nikita petrov’s picture

Status: Active » Fixed

Hi, sbilde!
You can use the code below to get the html content of your panel:

function mymodule_generate_panels_content($panel_machine_name, $node) {
  $task = page_manager_get_task($panel_machine_name);

  // Load the node into a context.
  ctools_include('context');
  ctools_include('context-task-handler');
  $contexts = ctools_context_handler_get_task_contexts($task, '', array($node));

  $output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
  if ($output !== FALSE) {
      return drupal_render($output['content']);
  }
  else {
    drupal_set_message(t('There is no content for that node!'), 'warning');
    drupal_goto(urlencode('node') . '/' . $node->nid);
    return;
  }
}

After that you can generate pdf file by calling pdf_using_mpdf_api($html, $filename) function.

If you need to add some more css to style your pdf exactly like according node's page, you should apply my patch from here, and then implement hook in your module like this:

function mymodule_mpdf_document_alter(&$mpdf_object) {
  // Setting CSS stylesheet to PDF.
  global $theme_path;
  $stylesheet_content = file_get_contents($theme_path . '/css/global.css');
  $mpdf_object->WriteHTML($stylesheet_content, 1);
}
sbilde’s picture

Thanks a lot for your reply Nikita. That is awesome! ..- I have a little hard time figuring out what the $panel_machine_name is? - Im trying to print a content type of 'Report' through as a Node view variant.

Can you point me in the right direction?

sbilde’s picture

Nevermind, I found it: node_view

Once again thanks for your help!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.