This module can be used as an API to generate print versions (for example PDF files), not only to view the current page (aka URL/PATH) with a specific version.

During generation, the module modifies current execution path with: menu_set_active_item(). This is done in order to obtain data such as title, breadcrumbs and other that are specific to the generated page.

This results in unexpected "redirects" when calling, for example, print_pdf_generate_path($path) on a path that is not the same as current path (for example generating PDF invoice to be attached to e-mail in a page post).

The solution is to restore original path after generation of print version has finished.

Patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcnventura’s picture

Issue summary: View changes
Status: Active » Needs review
gwalliman’s picture

I can confirm that this path solves the redirection problems for paths of the form "node/1", e.g. print_pdf_generate_path("node/1") works.
However, redirects still seem to occur if we prefix the path with another forward slash, e.g. print_pdf_generate_path("/node/1") still causes a redirect to "//node/1"

david_garcia’s picture

Is "/node/1" supposed to be a valid Drupal Path?

david_garcia’s picture

Found out why you are still getting redirected:

When the path is invalid, PDF generation fails, and the module, as a fallback method, redirects the user:

$pdf = print_pdf_generate_path($path, $query, $cid, $pdf_filename . '.pdf');
if ($pdf == NULL) {
drupal_goto($path);
exit;
}

in print_pdf.pages.inc

david_garcia’s picture

Rerolled the patch in GIT format and added some extra flavor...

[1] in print.pages.inc, original patch keeps track and restores original menu_item_active.

[2] in print_pdf.pages.inc when theming the node, make sure that the context of the node (theme, paths, etc..) are coherent with the path we are trying to generate.

david_garcia’s picture

I was not sure but... current module will redirect user to the requested PDF path when generation fails as stated in comment #4, that looks very wrong to me.

Or maybe we could add some control into that, maybe a flag to say if we want redirection on fail, but that better moved into a separate issue.

david_garcia’s picture

FileSize
1.91 KB

Previous patch was not rolled against latest dev...

david_garcia’s picture