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.


matthewgann’s picture

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.

lsolesen’s picture

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.

vladsh’s picture

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.

lsolesen’s picture

@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

vladsh’s picture

@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);

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.

s.Daniel’s picture

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

Not sure but this looks dangerous to me :o

giuvax’s picture

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.

benjmarr’s picture

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.

giuvax’s picture

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

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

Store Path

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"
killua99’s picture

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

ezman’s picture

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?

killua99’s picture

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.

ezman’s picture

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/

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.

killua99’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
rockaholiciam’s picture

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.

killua99’s picture

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.

ezman’s picture

If anyone needs a workaround for this, you can simply copy the code from views_pdf_rules_action_save() in 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:

$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.

sportel’s picture

@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).


vegansupreme’s picture

Issue summary: View changes

For at least some of the users in this issue, the problem appears to be related to
#2289779: Exploding Arguments in Rules Can Contain Carriage Return as well as new line
ezman, for example posted this "arguments" : "[node:author:name]\r\n[node:nid]",
This won't work the way the code currently works. Anyone else with this problem, please try the patch in the issue above. Alternatively, export your rule and then re-import it, but change "\r\n" to just "\n"

vegansupreme’s picture

killua99’s picture

kyleheney’s picture


I'm having the same issue (blank PDF saved to server). This only seems to happen when my View uses a Contextual Filter.

My view is of Webform Submissions and I'm trying to generate a PDF for each submission, then save each PDF to my server using Rules. In this case, my Contextual Filter is on the SID.

My rule uses "form-id" as the Views Argument (not sure if this is correct).

The PDF is generated correctly online, but the file that is saved to my server is blank.

Any help is appreciated.

yash_khandelwal’s picture

Download mpdf library from and include mpdf.php file.

Below is basic example to generate and blank pdf.

$mpdf=new mPDF();
yash_khandelwal’s picture

Status: Active » Closed (fixed)
matthewgann’s picture

Status: Closed (fixed) » Active
baldalo’s picture


I am still struggling with the blank page issue. I am working on this for a few and the issue comes and goes. After few tests I think this is not a privilege issue as my rule used to save correctly a PDF and suddenly stopped working after few changes somewhere else. I tried the user_load&drupal_session_regenerate thing and it helped in a rule but did not in a second. Then I read #17 and tried debugging the rule's code as follow:

    foreach ($view->display as $id => $display) {
      if ($display->display_plugin == 'pdf' && isset($display->handler)) {
      	dpm('Save PDF!');
        $display->handler->execute($path, 'F');

As my view has multiple PDF pages the dpm('Save PDF!') gets triggered multiple times. This just not look right to me. Can someone explain me why this has been coded like that?

Will try to play around it and will let you know.