The web generated PDF works great (with format mods, of course), but using a rule to save the PDF (which is is just saving a blank PDF. I've looked through forums and the bug reports but can't seem to find anything directly related. The correct passed variable to the view is also being used to generate the filename, so that seems to be working.

Comments

The event "Completing the checkout process" generates a blank PDF.

The event "When order is viewed" generates the PDF with data needed. All other settings are the same.

Status:Needs work» Active

Are you sure that all the relations are fulfilled when "Completing the checkout process" event fires the rule?

No patch to work on, so setting to active.

I have the same problem - invoice is viewed, but generated PDF file is blank. If I check "Disable SQL rewriting" in the query options of the view, file is populated with data, but there are no line items.

@vladsh It seems like a permission problem. Does the user have access to everything in the view when "completing the checkout process". If you want to show the line items, you should probably also disable sql rewriting on that included view. Though it is not good for security. #1535690: Permission to view PDF invoice should be restricted. Might also be, that this is your problem: #1794450: Line items not shown on the pdf

@lsolesen Thanks for the advice.
Seems that saved PDF has no line items due to the access restrictions:
commerce_paypal_wps invokes rules execution as an "Anonymous (not verified)" user.
I decided to sign in the user programmatically.
So, I've added "Execute custom PHP code" action just above the action "Save PDF as a file on the server":

global $user;
$user = user_load($commerce_order->uid);
drupal_session_regenerate();

If the user was signed in before the checkout, then all works as expected and PDF file is generated with the line items.

BUT if an Anonymous user performs the checkout, then blank PDF is generated.

<?php
global $user;
$user = user_load($commerce_order->uid);
drupal_session_regenerate();
?>

Not sure but this looks dangerous to me :o

I was also having the same problem, but I didn't have to disable sql rewriting.
I was simply using the wrong arguments in the 'save pdf to server' rule.
Now it generates the pdf correctly, with sql rewriting normally enabled.

would you mind sharing what the correct argument was in the rule?

and did you have any conditions?

could you also please export the rule and paste it here?

Thanks very much.

I simply edited the default rule "Send an invoice notification e-mail (HTML)" inside Commerce Invoice module.

I added this Action before the "Send mail with Variable" one.

Editing action "Save PDF as file on server"

Views Arguments
[commerce-invoice:uid]
[commerce-invoice:invoice-id]

(since my pdf has url user/%fatture/%, fatture=invoices)

Store Path
privato/fatture/[site:name]-[commerce-invoice:invoice-number]

Here it is:

{ "commerce_invoice_email_invoice_html" : {
    "LABEL" : "Send an invoice notification e-mail (HTML)",
    "PLUGIN" : "reaction rule",
    "WEIGHT" : "9",
    "REQUIRES" : [ "rules", "views_pdf", "variable_email", "entity" ],
    "ON" : [ "commerce_invoice_insert" ],
    "DO" : [
      { "views_pdf_rules_action_save" : {
          "views_pdf" : "fattura_utente:pdf_1",
          "arguments" : "[commerce-invoice:uid]\r\n[commerce-invoice:invoice-id]",
          "path" : "privato\/fatture\/[site:name]-[commerce-invoice:invoice-number]"
        }
      },
      { "variable_email_mail" : {
          "to" : "[commerce-invoice:order:mail]",
          "variable" : "commerce_invoice_email_invoice_[mail_part]",
          "language" : "default",
          "from" : "[site:name] \u003CXXX@XXXX.XXX\u003E"
        }
      }
    ]
  }
}

Status:Active» Postponed (maintainer needs more info)
Issue tags:+Needs steps to reproduce

Dear fellow Drupal enthusiasts,

I have set this issue to "Postponed (Maintainer needs more information)".

If not already done please add an issue summary and steps how to reproduce the problem.
And please read again, "Making an issue report".

Help about how to do this can be found on IRC and in the user groups.

After there is new information, please re-open the issue by changing the status to active.

--
This issue was edited with the help of Issue Helper

Status:Postponed (maintainer needs more info)» Active

I'm having this problem with my PDF view.
My view accepts two parameters: user name and node id
It usually gets these from the path: users/%/memoirs/%/pdf
The user name is the name of the user rather than the uid.

Here's my rule. I've tried various different ways of trying to get the username in there, node:author:name, node:field-author, current-user:name (as the view is triggered by the logged in user saving their node) but none work - every time I get a blank PDF. More specifically, a PDF of 6320 bytes in size.

{ "rules_update_memoir_pages" : {
    "LABEL" : "Update memoir pages",
    "PLUGIN" : "reaction rule",
    "TAGS" : [ "memoir" ],
    "REQUIRES" : [ "rules", "views_pdf" ],
    "ON" : [ "node_update", "node_insert" ],
    "IF" : [
      { "node_is_of_type" : { "node" : [ "node" ], "type" : { "value" : { "memoir" : "memoir" } } } }
    ],
    "DO" : [
      { "views_pdf_rules_action_save" : {
          "views_pdf" : "memoirs:pdf_1",
          "arguments" : "[node:author:name]\r\n[node:nid]",
          "path" : "\/tmp\/[node:nid].pdf"
        }
      }
    ]
  }
}

Relevant module versions:

views_pdf 7.x-1.1
views 7.x-3.7
rules 7.x-2.3

Is there something to comment #5 ? My rule only gets triggered when an authenticated user saves a node, but does it get run as anonymous by Rules?

Is something about the file system in drupal.

I have to find a way to "bypass" it when the cron process or other allowed process is running. With this information now we have something to digg in.

This additional info may help. I've tried using the advice in #5, and then tried a 'better' method, using Rules Switch User
Both methods achieve functionally the same thing: authenticate as another user while running the rule.

When my rule runs, I now see this error in the log:

Notice: Undefined offset: 0 in views_pdf_plugin_style_unformatted->render_grouping_sets() (line 48 of /sites/all/modules/views_pdf/views_pdf_plugin_style_unformatted.inc).

The same empty PDF file is created as before.

Interestingly, I have a function that runs on hook_views_post_render, which updates a value on the node. This function gets called and run successfully, and is able to access the $view->pdf object (it's querying $view->pdf->getNumPages() ), so something's working correctly.

As a workaround I tried using fopen() to get the PDF from its URL, but that failed with a 403 even when impersonating the node's author.
So maybe the views permissions system is the culprit here? (My view in question has permissions set to "view own unpublished content")

Hope this additonal info helps.

Version:7.x-1.x-dev» 7.x-2.x-dev

Version:7.x-2.x-dev» 7.x-1.1
Category:support» bug
Priority:Normal» Major

Same issue as described. The link displays the pdf fine but if you try to save it on server via the rule, it displays empty though it does display the template if set. Doesn't seem to be a permission issue.

Version:7.x-1.1» 7.x-2.x-dev
Category:bug» feature
Priority:Major» Normal
Issue tags:-#views_pdf_7.x-2.x

This is a feature request. The current branch didn't support it.

Next version 2.x will

Keep it like this. I'll not develop any solution for the 1.x branch.

If anyone needs a workaround for this, you can simply copy the code from views_pdf_rules_action_save() in views_pdf.rules.inc into your custom module.

In my implementation I need to generate the PDF when the user adds it to their Commerce shopping cart, so I've stuck the code in function MYMODULE_add_to_cart($form, &$form_state)

My PDF view needs the user name and node id as contextual arguments, so I pass them like this:

<?php
$nodeid
= intval( $form_state['node']->nid );
$username = $GLOBALS['user']->name;
$view = views_get_view('VIEWNAME');
$view->set_arguments( array( $username, $nodeid ) );
?>

(This part replaces views_pdf_rules_action_save()'s way of passing arguments. After this the rest of the code is the same.)

This does what the Rule should do.

@ezman (#13):

Thanks, the Rules Switch User module works for me.

My rule for saving a PDF is mostly executed by an anonymous user, who doesn't have the proper permissions which results in a blank PDF. But with the Rules Switch User module I can make sure the rule is always executed with the right permissions (from another user).

Mike.