On a site with extensive use of Panels3, I also have a critical need to print to PDF.

We have a content type=Project, and a Panels treatment of the node. I have placed the PDF link onto the Panels layout, and the link shows up on the final output.

However, the print action is actually using the base node, not the Panel's layout.

Can I get the print action on the Panel level instead?

Using wkhtmltoPDF.

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

Can you provide a URL to the page?

boabjohn’s picture

Howdy JCV: thanks for checking...the page is behind a security layer at the moment. It's a normal panel page, and as merlinofchaos notes, panel pages are not nodes.

The Print module can be invoked with printpdf/[nodeID] (only?)

So there seems to be no way to address the current state of the user's screen, which is being rendered though Panels, not through a node.

Have you been able to get a panel page to print with wkhtmltopdf?

Thanks, JB

jcnventura’s picture

No, you can also access pages via printpdf/path.

To show links in those pages you need to enable the appropriate setting in the module settings.

boabjohn’s picture

Ahhh! That sounds like the go: but where in the settings? I've been through the common settings and the PDF settings. Sorry for being blind, but can you please show me where to change/set this?

Thanks!

boabjohn’s picture

Right: never mind...found it!
PDF Settings> Advanced options> Use URL alias instead of node ID

Sorry for the hassle...

FWIW, I started a thread over with the Panels people as well on this point: I'll share this tidbit with them.

Thanks again,

JB

boabjohn’s picture

But: we're back.

Yes, even though the option is ticked, and the bottom of the PDF shows that it used the URL and not the node ID, the proble is that it is still feeding off of the *nodes content* vs all the rich relational content I have dragged into the panel page.

The panel page is rendered whenever a node of type x is called.

So the node content is one layer

The Panel pages sits on top and assembles views etc (along with native node content).

What I want is for the user to get the Panel page assembly, not just the node content...and the URL path trick is not doing the trick (sad to report!)

JB

boabjohn’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Just to complete this one...

There's no underlying problem with any of the Print module gear here. The hard fact is that producing a nice PDF version requires hand coding of a specific template.

We opened up our nice Panel page display and went through each content area, creating php calls in the pdf template. If we make changes to the cck/node/view assembly, then these changes have to be separately managed in the PDF template as well.

Closing...

Exploratus’s picture

I agree with #6. Printing just node content vs a cobination of views / node content is very different and very important. I want to be able to pdf print a particular set of views.

Is is possible to print a particular set of views related to a node with the module as it stands now? Considering trying it out, but if it can print a certain type of views, wont do me any good.

Any suggestions?

boabjohn’s picture

@whatmetropolis: as I understand it, thesystem works as follows...

1. The prin module takes the url (with node value) and has a quick look for any custom print stylesheets that might exist *for the target node type*.

So if you're printing a node of type = media_release, Print will look for a media_release-print.tpl.php (or something close to that)

2. This template can carry whatever php you wish to include...which means you can call whatever views with whatever parameters you're able to code for.

So on the one hand it's a manual coding job, buit on the other you get to do whatever you like...

A themer is probably the person you need. Someone to connect the views with the print tpl.

HTH.

Andy_Read’s picture

The Print/PDF module is great, but like others before me I've hit this same problem.
From my own experiments, it appears that the module is quite happy to render the output of a regular Panels page with a dedicated url path, it's just when using a Panel node that the Print module 'chooses' to use the raw node instead of waiting until Panels has done its stuff.

I'm going to dig into the code a bit, but in principle it seems that the Print module is quite capable of rendering the Panel node output but maybe needs a switch to tell it to do this instead of the raw node. Everyone on this thread would probably say it should default to taking the output from Panels, just as you see in the browser, but if a switch is needed it could be in the print settings or even per content type.

Andy

Andy_Read’s picture

Yes, indeed! There may be subtleties I'm not yet aware of, but looking at print_controller() in print.pages.inc, the code has 3 options to process the page: _print_generate_node(), _print_generate_book() and _print_generate_path(). The current logic gives the simple node generation priority, then book (not sure how that differs) and finally path is treated like a poor-man's fallback. A quick hack to make _print_generate_path() the first choice happily created print and PDF versions of a Panels node page.

So it's just a case of refining this logic with some admin settings...

Andy

Andy_Read’s picture

Status: Closed (fixed) » Active

Having re-opened this issue, I've re-linked and highlighted this update on the duplicate issue #890596: How to print Panels output?.

As previously stated, it's simple to patch the print_controller() function to use the Panels output for nodes, but I wanted to get some input on reqs/spec before suggesting a specific patch. When should the print module take Panels output rather than node-specific output?

What additional admin setting might be required according to your use-cases?

ayalon’s picture

I wrote a patch, that implements panels support.
It's only a few lines long.
I think it's better, not to change the logic of the print_controller(). The patch has only a impact, if panels is installed.

boabjohn’s picture

Hi guys...as the issue originator 1.5 years ago (!) it's great to see the new thinking here...especially appreciate andy_read and ayalon grabbing the issue by both ends and having a go.

I'm a non coder: it looks to me like there is the stub of an idea offered by the existing option to: PDF Settings> Advanced options> Use URL alias instead of node ID

Isn't this the "switch" point needed? The problem (back in 2009) was that despite using this option we still got the raw node.

If the #13 patch forces PrintPDF to use the URL alias (ie, the final rendered page) that means there's no need for additional interface/management work. Just add a comment to the Use URL option noting the effect of providing a solution for Panels (and other rendered elements).

dogboy72’s picture

Patch in #13 works well. I had been using custom .tpl files (i.e. print_pdf.node-MY_CONTENT_TYPE.tpl.php) but the patch defaults to the print.tpl.php. Anyone know if there is a way to override this and create custom tpl files?

StratisFear’s picture

Can someone adapt this patch to print_mail.inc file so that it works with send mail and not just print?

HnLn’s picture

#13 also seems to work for d7 except that the check on the page callback should be for 'page_manager_node_view_page' (line 95).

jcnventura’s picture

Status: Active » Needs review
rfulcher’s picture

I have put this patch in place and see no difference. I have a panel with a node displayed and a view at the bottom. I really need the PDF & Print & Email to include the view at the bottom....Help I am new to this so I am hoping I put it in the right spot in the file.

dhayalan_ms’s picture

It can be easily achieved by having no hacks using print.node-type.tpl.php

Just follow the steps mentioned below

1.copy print.node-type.tpl.php into theme
2.Create a function as follows in template.php

<?php
function get_panel_view(&$node) {
	// Load my task plugin
	$task = page_manager_get_task('node_view');
	

	// 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), false);
	if ($output !== FALSE) {
		return $output['content'];
	}
	// Otherwise, fall back.
	return node_view($node);
}
?>

3.In print.node-type.tpl.php replace print $print['content'] into print get_panel_view($print['node']);

4.Rebuild theme cache

5.You are done

dreamer777’s picture

dhayalan_ms. thank you very much! you made my day!

#20 works perfect for print page. I will try it for pdf and e-mail also and let you know.

dadderley’s picture

Have you made this work with Drupal 7? The same problem exists there as well.
Thanks in advance.

dhayalan_ms’s picture

@dougzilla ,Sorry I havent tried in Drupal 7, I will look into it and let you know inb couple of days

dadderley’s picture

Thank you.
I really appreciate you revisiting this issue.

annikaC’s picture

Hi dougzilla,

Stumbled across this while looking for the same thing - thanks to dhayalan_ms for D6 code, here's that function for D7:

function get_panel_view(&$node) {
    // Load my task plugin
    $task = page_manager_get_task('node_view');
   

    // 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']);
    }
    // Otherwise, fall back.
    return drupal_render(node_view(node_load($node->nid)));
}

Template should be called print--node--[type].tpl.php. Hope that helps you or anyone else with the problem out!

dadderley’s picture

Hi annikaC,
Thank you.
This is lovely. It does have a quirk though.

When logged in as user 1, it works perfectly.
When not logged in or logged in as another user, this error shows up when I hit the "printer friendly" and "pdf version" links.

Fatal error: Only variables can be passed by reference in /home/myuser/public_html/ski/sites/all/themes/sparwood_standard/template.php on line 25

In my template file, line 25 is in here.

$output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
if ($output !== FALSE) {
	return drupal_render($output['content']);
}

Have you encountered this?
I looked at the permissions, everything should be good.

annikaC’s picture

Good spot! I will have another look at this tomorrow as it was for one of my current projects :)

dadderley’s picture

Cool and thanks again, I am pretty excited about this.

annikaC’s picture

Back again - I am uncomfortable with this solution but it works - anyone got a better way? Does it work for you dougzilla?

function get_panel_view(&$node) {
    // Load my task plugin
    $task = page_manager_get_task('node_view');
   

    // 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) {
      if (user_access('administer site configuration')) {
        return drupal_render($output['content']);
      }
      else{
        return $output; 
      }
    }
    // Otherwise, fall back.
    return drupal_render(node_view(node_load($node->nid)));
}
dadderley’s picture

Yes annikaC it works for anonymous and authenticated users.
Good work, thank you.

Peacog’s picture

Hi annikaC and dougzilla

I'm trying to use your code but I can't get it to pick up my template. I've tried print--mynodetype--.tpl.php and print--mynodetype.tpl.php. What's the correct format? Thanks.

Peacog’s picture

I should have read the README first. All the valid formats are there. For a content-type specific template it's print--node--[type].tpl.php. For a format specific and content type template it's print--[format]--node--[type].tpl.php for example print--pdf--node--article.tpl.php.

dadderley’s picture

@Peacog
Just saw your post.
Glad you figured it out.
annikaC rocks!

jwilson3’s picture

Status: Needs review » Needs work

I tried the patch in #13, updating it for Drupal 7, but it doesnt work appropriately, because as soon as you enable Panels node variants, the page callback gets added *everywhere* even if the current node type doesnt have a variant. Thus, I've gone with the other more recent code snippets, but have cleaned them up a bit to take advantage of not having to generate the content twice, as most of the examples above do.

This example implements hook_preprocess_print() function, and can be placed in your theme, without having to modify the print templates at all, as it modifies the $print['content'] variable, before getting to the template layer.

/**
 * Implements hook_preprocess_print().
 */
function mytheme_preprocess_print(&$variables) {

  // All our nodes use Panels, which we want to also use to render the print
  // and printpdf main content sections.  If you need to you could modify
  // this if statement to limit this to certain node types.
  if (isset($variables['node'])) {
    $node = $variables['node'];
    // Load the panels node view task plugin.
    $task = page_manager_get_task('node_view');

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

    // Attempt to render the node with its contexts using CTools.
    $output = ctools_context_handler_render($task, '', $contexts, array($node->nid));
    if ($output !== FALSE) {
      if (user_access('administer site configuration')) {
        $variables['print']['content'] = drupal_render($output['content']);
      }
      else {
        $variables['print']['content'] = $output;
      }
    }
  }
}

I'm placing this as CNR, because this currently only handles the "node_view" panels, and doesn't work for other object type variants like User pages and taxonomy term pages that could possibly also be using Panels for render as well.

bradjones1’s picture

Version: 6.x-1.x-dev » 7.x-2.x-dev
Status: Needs work » Needs review
FileSize
2.2 KB

Bumping this to 7.x since there doesn't seem to be consensus code for 6 and a good solution can likely be backported.

By my analysis this issue boils down mostly to selecting (and using) the proper menu router callback for the node in question, much as would happen by default for a non-node custom page. So why not just set an option for nodes to bypass their special handling in print module and just consult the menu router as to which callback to use?

See attached patch. Thanks!

developerweeks’s picture

Perfect timing for this patch and discussion, attempting this patch on 7.x-2.0-beta2.
I think either I missed something, or there is a step missing in the patch. Something in my site is not handling this as expected. Attempted the pdf print gives me an end result of 'The requested page "/printpdf/234" could not be found.'

I tried tracing this workflow, and I am wondering how this patch is supposed to accomplish the pdf render of the panel. I see how this excludes the removal of 'node' from the front of the path, and how this prevents the call of _print_generate_node, thus forcing the print module to use _print_generate_path.

However, from the behavior of my browser I have to assume _generate_path is failing and I am seeing the alternate:
$node = print_controller($path, $link['format'], $cid, $view_mode);
if ($node) {
...
}
else {
return NULL;
}

Triggering this catch:
$pdf = print_pdf_generate_path($path, $query, $cid, $pdf_filename . '.pdf');
if ($pdf == NULL) {
drupal_goto($path);
exit;
}
Far back in scope where $path equals "234" (never passed by reference).
And since drupal_goto("234"); does nothing, I get my error message.

If I do not alter the line
if (ctype_digit($parts[0]) && ((count($parts) == 1) || $revision_view)) {
then the pdf link only refreshes the page.

Is this patch working for some one else?

jwilson3’s picture

Status: Needs work » Needs review

On a separate project from the implementation I used/suggested in #34 and so I had an opportunity to try out the patch in #35, with Panelizer for the node rendering, instead of normal Panels node_view variants.

I can concur with #36. The patch only works when you enable the setting "Use URL alias instead of node ID" on admin/config/user-interface/print/ui "Advanced link options".

If you try to use printpdf/[nid], you end up with an error, but if you go to printpdf/[node-alias] (assuming you have pathauto configured) everything works great.

Additionally, if you go to printpdf/node/[nid] the patch works fine as well.

It all has to do with the stripping of the "node/" from the URL.

jwilson3’s picture

Status: Needs review » Needs work

I edited my comment above because I found the same bug as #36. CNW

brockfanning’s picture

Issue summary: View changes
FileSize
2.74 KB

Here's a slight tweak of bradjones1's patch, to address that page-not-found issue.

By the way, the approach bradjones1 uses strikes me as something that should just be the default, with no need for a UI checkbox. Is there any downside to consulting the menu router like this 100% of the time?

Yuri’s picture

When I apply patch #39, it does not have any effect and pdf print still shows only the node contents, not the panel panes of the node virant panel. Does any of you have success with latest print module dev. and panels?

Yuri’s picture

Status: Needs review » Active
bradjones1’s picture

@Yuri - did you toggle the checkbox this patch adds to the admin config ("Consult menu router..."?)

Yuri’s picture

@bradjones1 Thank you, after checking that box, the page indeed shows up in the generated pdf.
However, that includes also some panes and also the 'text format' information..is there a way to select what appears and what not?
Thanks!

bradjones1’s picture

Status: Active » Needs review

@Yuri - I'm not entirely sure what you mean by extra panes and test formats... but I suppose you could implement a print stylesheet in addition to using this module. Regardless, I think given you're feedback it's safe to put this back to "needs review."

If a maintainer could take a look at this since it seems to work for multiple others?

baschke’s picture

the patch from #39 isnt't working with the latest version of the module.
I get an error when patching:

patching file print.pages.inc
Hunk #1 FAILED at 87.
Hunk #2 succeeded at 636 with fuzz 1 (offset -41 lines).
1 out of 2 hunks FAILED -- saving rejects to file print.pages.inc.rej

could anyone have a look into this?

dobe’s picture

Patch in #39 worked for me. Thankyou!

-Jesse

mccrodp’s picture

Patch in #39 did work for me and also applied cleanly to the latest dev version from git repo. The new option will work with Panels that override the node content area such as Panelizer in my case. But it will not work with Panels Everywhere module.

candelas’s picture

@baschke the errors that you get are because you applied to version 7.x.1-dev or whatever of the 1 release. This patch work for the 7.x-2.x-dev

#39 worked for me too.

candelas’s picture

Status: Needs review » Reviewed & tested by the community

I tested in last Open Atrium distribution and works with one patch to fix a couple of things (if you are interested, look in the OA_print module issue cue).
Thanks to all for collaborating making this patch. The only thing is I would never have guessed that that change on the menu router would let me print with Panels. So much to learn in Drupal!

I think this is an important patch to communicate two solid modules as Print and Panels, that are with us for many years, always updating and letting us work faster. It would be very good if this is included in Print.

jwilson3’s picture

Priority: Normal » Major

based on #49, yes, this would be a pretty major win.

katrien_w’s picture

@Candelas: could you be so kind to provide steps to get print working with Open Atrium, for instance for a panelized OA section page.
OA print only prints document pages as far as I know?
Which pdf library do you use?

candelas’s picture

@katrien_w here #2452737: OA Print: update to Print 2 and apply a patch to work with Panels I explained, point the patches I used and made one. If you have any doubt, I think it is better to answer there to centralize the information :)

boabjohn’s picture

G'Day all,
Nice to come back to a healthy and productive discussion after 6 years! It turns out a current project could very much use this feature so here I am again to see what has been offered up by the ever-generous Drupal Community.
This is likely to be a personal problem, but I've tried clearing out my local repo and re-installing the latest 7.x-2.x-dev, and then applying the #39 patch. I got what looks like partial success:

$ patch -p1 < 565856-panel_support_print-39.patch
patching file `print.admin.inc'
patching file `print.module'
patching file `print.pages.inc'
patch unexpectedly ends in middle of line
Hunk #2 succeeded at 677 with fuzz 1.

Would there be an obvious explanation for this unexpected ending? I'm not a patch master...
Thanks in advance for any clues.
Kind regards,
JB

boabjohn’s picture

Also, @mccrodp, what was the specific problem you were seeing with Panels Everywhere, referenced in #47?

We're often in the position of needing to wrap PE around a site.

mortona2k’s picture

@boabjohn

I just tried patch -p1 < 565856-panel_support_print-39.patch

Patch applied cleanly for me, from within the print module directory.

katrien_w’s picture

Hello, thanks for all the usefull efforts in this discussion.
A single panelized page prints flawless with the latest patch. But when I'm using the 'printfriendly version' on a book page, I'm still getting the node contents of the parent page and its children in one list, instead of the panelized page versions.

I know that the print module should be taking over partly the print function of the book module.
I'm not a coder. Maybe someone can help me on this?

mccrodp’s picture

@boabjohn - Sorry for delay, I don't have access to the project I was working on anymore and I cannot remember to give you exact info.

I remember I figured out why, but did not find a solution as far as I remember. It was either that Panels Everywhere uses a different preprocess function or tpl file to Panels / Panelizer. So, it only looked into the content region that Panels / Panelizer overrides rather than say blocks that are added by Panels Everywhere to the content region or elsewhere. Good luck!

P2790’s picture

The patch works great for me, but I am losing the Node Title on my panelized content types. I have a workaround where I hide provide the title from a panel pane and put the title in the content area of the panel. I am using panelizer and the bootstrap theme, although having tested other themes it is not theme related.

P2790’s picture

Status: Reviewed & tested by the community » Needs review

Changing to needs review.

izmeez’s picture

I would appreciate some clarification on naming conventions for custom theme template files.

The README.txt file suggests naming the files as:
print-node-content-type.tpl.php

Meanwhile comment #9 above #565856-9: Can Panel pages be sent to PDF for rendering? suggests naming custom template files as:

content-type-print.tpl.php

and suggests that the module automatically uses these custom template files if they exist for different content-types allowing them to be used for printing panels layouts and other enhanced layouts rather than simply printing the node.

There may be specific advantages and use cases for the different naming conventions.

There is also a suggestion in comment #14 above #565856-14: Can Panel pages be sent to PDF for rendering?
that what is needed is simply a help comment

Just add a comment to the Use URL option noting the effect of providing a solution for Panels (and other rendered elements).

Would it be useful to add a few lines to the help for the module?

A separate issue could be started for that purpose.

izmeez’s picture

Following on comment #60, I have created a separate issue to enhance the help documentation and at the same time make it available when the README.txt file is not readable #2787263: Provide print module help when README.txt file not readable on some production sites.

wizonesolutions’s picture

Status: Needs review » Reviewed & tested by the community

IMO this patch is Good Enough™. Worked for me as I expected. I vote for getting it in.

pinueve’s picture

+1 patch #39 works perfect, but it does apply on 7.x-2.0 and NOT on dev version

jcnventura’s picture

Status: Reviewed & tested by the community » Fixed

Fixed #39 to make it apply, and committed it. Thanks everyone!

P2790’s picture

Status: Fixed » Needs review

@jcventura

See my comment:

The patch works great for me, but I am losing the Node Title on my panelized content types. I have a workaround where I hide provide the title from a panel pane and put the title in the content area of the panel. I am using panelizer and the bootstrap theme, although having tested other themes it is not theme related.

Can anyone else confirm they have this issue?

daggerhart’s picture

This is off topic from the submitted patch, but I thought it might be worth showing an alternate approach. I created a panels rendering pipeline that uses functionality provided by the print_pdf module.

https://github.com/daggerhart/panels_printpdf

crutch’s picture

Daggerhart, I tried panels_printpdf, it still renders only the node and not the panel content including any views. Also, it dedicates the Panel variant as only a PDF and so you are unable to view the page. Maybe I'm doing something wrong, however I like the approach and it works to render a panel variant as a PDF and has a straight forward configuration.

crutch’s picture

Patch #64 on 2.x dev seems to be working well after a few days of getting familiar with the current state and getting things configured properly, thanks!

crutch’s picture

Yes I can confirm the same @#66.

The title will display when removing <?php if (!isset($node->type)): ?> and <?php endif; ?> around the h2 print-title in the tpl.php

P2790’s picture

@crutch, thanks for that, which tpl file do you mean? Is it the one in the module, print.tpl.php

crutch’s picture

yes, however I copied print.tpl.php over to sites/all/themes/mytheme/templates folder and then made the customization there.

I now have print--pdf.tpl.php and print--html.tpl.php in my theme (flush caches after copying and every time after changing code in those files to activate them).

jcnventura’s picture

Fixed, as per #65

jcnventura’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

kopeboy’s picture

I don't understand how I can print the Panel output of the node.

I've updated to dev version of the module.
And it doesn't work out-of-the-box:
the pdf print i'm testing is still showing the node content and not anything else I've added to the panel variant.

Then I tried adding the function of comment #29 in my theme's template.php file

Then I tried replacing 'print $content' with 'print get_panel_view($node)' in the module's print.tpl.php
(I don't have any node template in my theme that is overriding that)

And the result is still the same.
Can anybody help please?