Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #1
matthewgann CreditAttribution: matthewgann commentedThe 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.
Comment #2
lsolesen CreditAttribution: lsolesen commentedAre 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.
Comment #3
vladsh CreditAttribution: vladsh commentedI 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.
Comment #4
lsolesen CreditAttribution: lsolesen commented@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
Comment #5
vladsh CreditAttribution: vladsh commented@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":
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.
Comment #6
s.Daniel CreditAttribution: s.Daniel commentedNot sure but this looks dangerous to me :o
Comment #7
giuvax CreditAttribution: giuvax commentedI 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.
Comment #8
benjmarr CreditAttribution: benjmarr commentedwould 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.
Comment #9
giuvax CreditAttribution: giuvax commentedI 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:
Comment #10
killua99 CreditAttribution: killua99 commentedDear 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
Comment #11
ezman CreditAttribution: ezman commentedI'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.
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?
Comment #12
killua99 CreditAttribution: killua99 commentedIs 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.
Comment #13
ezman CreditAttribution: ezman commentedThis 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:
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.
Comment #14
killua99 CreditAttribution: killua99 commentedComment #15
rockaholiciam CreditAttribution: rockaholiciam commentedSame 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.
Comment #16
killua99 CreditAttribution: killua99 commentedThis 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.
Comment #17
ezman CreditAttribution: ezman commentedIf 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:
(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.
Comment #18
sportel CreditAttribution: sportel commented@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.
Comment #19
vegansupreme CreditAttribution: vegansupreme commentedFor 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"
Comment #20
vegansupreme CreditAttribution: vegansupreme commentedComment #21
killua99 CreditAttribution: killua99 commentedComment #22
kyleheney CreditAttribution: kyleheney commentedHi,
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.
Comment #23
yash_khandelwalDownload mpdf library from http://www.mpdf1.com/mpdf/index.php and include mpdf.php file.
Below is basic example to generate and blank pdf.
Comment #24
yash_khandelwalComment #25
matthewgann CreditAttribution: matthewgann commentedComment #26
baldalo CreditAttribution: baldalo as a volunteer commentedHi,
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:
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.
L.
Comment #27
RickJ CreditAttribution: RickJ commented