I needed to email a PDF by mail, so I added some Rules support in order to do this.

Thanks to @cgdrupalkwk who sponsored some development on the original patch to create module, there's now a pretty nice working module: Rules download

Comments

hanoii’s picture

Status: Active » Needs review
StatusFileSize
new2.21 KB
ocanzillon’s picture

Status: Needs review » Needs work

When you use this action twice in the same rule, you get the following error messages:

  • Notice : Constant K_TCPDF_EXTERNAL_CONFIG already defined dans _print_pdf_tcpdf() (ligne 269 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_PATH_MAIN already defined dans _print_pdf_tcpdf() (ligne 270 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_PATH_URL already defined dans _print_pdf_tcpdf() (ligne 271 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_PATH_FONTS already defined dans _print_pdf_tcpdf() (ligne 272 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_PATH_CACHE already defined dans _print_pdf_tcpdf() (ligne 273 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_PATH_IMAGES already defined dans _print_pdf_tcpdf() (ligne 274 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_BLANK_IMAGE already defined dans _print_pdf_tcpdf() (ligne 275 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_CELL_HEIGHT_RATIO already defined dans _print_pdf_tcpdf() (ligne 276 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).
  • Notice : Constant K_SMALL_RATIO already defined dans _print_pdf_tcpdf() (ligne 277 dans .../sites/all/modules/print/print_pdf/print_pdf.pages.inc).

Something seems to be loaded twice.

ocanzillon’s picture

There is another interesting use case which is to save a path as a temporary PDF. This is very useful when you created panels to present some information outside a node view. I refactored a little bit your code, because the basis is the same between generating a PDF from a node or from a path.
Sorry I can't make a git patch, so I provide you a diff between my file and yours. Hope this helps.

daniorama’s picture

Hello, I would like to know if I could use this combined with VBO, token and Rules to create multiple PDF in batch based on a node template with tokens. I would like a way to send mass notifications by email but also by post and I would like to have a PDF file with all the letters joined into a file that it's saved on the server so I could download it later to print it.

Could you include those features and/or tell me how could I manage that? I think a lot of people would be really interested in this feature. Thanks

cgdrupalkwk’s picture

Hi,

I'd like to sponsor the advancement of the Rule Integration of this Module. I to have the need to email PDFs created by this module and also would like the ability to use Rules to add these Files to File Fields of existing or new Nodes. The current Patch appears to focus on PDFs generated from Nodes, while I would also like to extend the functionality to work with PDFs generated using Views (which I think is much easier to do this this Module than with Views PDF).

I'd like to have a Rules Action that allows the following to take place:
1. Specify the URL of the PDF View to be saved (example= printpdf/"View path set on Views Page/Contextual File Arguments" or the path to a PDF Node Page - Tokens would be used to build the URL as needed)
2. Have the PDF generated by the above URL saved to the Server and added to the "file_managed" table (so a FID is created and associated with the File)
3. Have the newly created FID be available for use as a Varible by other Rules Actions
3. Once Step #3 is completed by the Rule the File would be able to be attached to a File Field and could easily be sent as an email attachment using existing Rules functionality

I am not a developer but appreciate the time and effort all of the talented developers in this community put into developing and maintaining the awesome functionality Drupal offers. If you are interested in adding this functionality to the existing module or creating a sub module please let me know how much money you would like to do so and if it sounds fair i'll gladly pay for your help and hard work.

Thanks,

Kyle

mudsurfer’s picture

Kyle, check https://drupal.org/project/pdf_archive. I commissioned that one with very similar requirements.

cgdrupalkwk’s picture

Mudsurfer,

Thanks for your response. I checked out the PDF Archive and it appears to only work with Entities, not Views. Do you know of a way to use this to save Views as PDFs? I did see an issue in the que asking about using the Views Field but I would like to avoid this.

Thanks again for your help,

Kyle

cgdrupalkwk’s picture

Is anybody interested in working on this? If so let me know how much $ you'd like (see #5).

Thanks!

sebastiannm’s picture

Patch #3 doesn't work any more with the latest version of mimemail

cgdrupalkwk’s picture

Title: Some Print PDF Rules integration » Some Print PDF Rules integration (Willing to sponsor advancement of this)
Version: 7.x-1.x-dev » 7.x-2.x-dev
Issue summary: View changes

Hi,

I still would like to see this feature be implemented as part of this module or a sub-module (See #5). I'm willing to pay up to $500.00 if anyone is interested in working on this. If so please let me know.

Thanks,

Kyle

hanoii’s picture

@cgdrupalkwk hi, I am the original submitter of this issue. It's been a while since I worked on this but I am interested in seeing this through and your sponsor offer looks interested, I am worried, however, that there might be more issues into this, but I am willing to take a bit of a look, let me know if you are still interested and if you are not already received interest from any other dev. Also, I will appreciate if you are there to do tests and stuff. The main issue is generating the PDF out of views, because I think it's not a standard functionality of Print and thus the module will have to add more functionality that a mere rules integration, this is my main concern but I would think it should be doable.

cgdrupalkwk’s picture

@ Hanoii,

Thanks for responding to my offer. I'm excited about your interest in finishing this feature and will definitely be able to test.

This module does allow generating PDfs from Views out of the box. All you have to do is add "printpdf" before your normal view path (Example = "www.drupalsite.com/printpdf/viewpath"). When configuring the link to your View page in Views you do not put "PrintPDF" anywhere in the link path. I find dompdf works best when using this module with Views.

Let me know once you've had a chance to look into this and if you're still interested we'll work out payment details.

Thanks again!

Kyle

cgdrupalkwk’s picture

Hi Hanoii,

Just checking in to see if you're still interested in my offer. Are you?

Kyle

hanoii’s picture

I am yes, probably will look at it this week.

hanoii’s picture

@cgdrupalkwk sorry for the delay, I am not setting up a dev env to look this through, still interested/not doing it with someone else?

hanoii’s picture

@cgdrupalkwk only a quick mail to let you know that I made very good progress, I might have something to show you by the weekend or early next week. If you want, you can contact me through my drupal contact page and we can follow things up by mail, although we can work on the specifics of the issue here.

cgdrupalkwk’s picture

Hi, I am still interested. I will send you an email later tonight.

hanoii’s picture

@cgdrupalkwk, ok, will wait for your mail, in the meantime there's a pretty nice module waiting for you to try, do you know how to checkout a project with git? If so, you can check https://drupal.org/sandbox/hanoii/2243965 and let me know what you think.

cgdrupalkwk’s picture

Hi,

I tried the module and really like how you set-up the parameters of the Rules Action.

I am experiencing a problem. I setup a basic Rule that executes this new Rules Action when "Content is Viewed". When the Rule fires the PDF that is to be generated opens up on the screen and the File is not added to the system. I used the internal path of a View as the PDF to generate ("printpdf/viewpath"). I tries the Event "Before Saving Content" and got the same result.

Is there any other info I can provide you to help troubleshoot?

Kyle

hanoii’s picture

Do not use "printpdf/viewpath", use just "viewpath" and let me know if that works for you.

hanoii’s picture

Just added a validation to prevent the user from doing that. I think that should be it.

hanoii’s picture

Issue summary: View changes
hanoii’s picture

Title: Some Print PDF Rules integration (Willing to sponsor advancement of this) » Print PDF Rules integration

Moving it to my own now.

hanoii’s picture

Title: Print PDF Rules integration » Some Print PDF Rules integration (Willing to sponsor advancement of this)
Project: Printer, email and PDF versions » Rules download
Version: 7.x-2.x-dev »

Oops, restoring title.

Some Print PDF Rules integration (Willing to sponsor advancement of this)

cgdrupalkwk’s picture

Hi,

Not using "printpdf" as part of the path worked and the Rule successfully created the File Entity. Thanks for adding the validation feature!

cgdrupalkwk’s picture

Hi,

I am having another problem. After the Rule runs the Page Title of the View used to generate the PDF shows up instead of the Node Title. Example as follows:
-I created a test site only using the Modules required to use Print, Views, Rules, and this Module
-I setup a View that display a unformatted list of Node Title and called the View "Test Content"
-I setup a simple Rule to execute the Rule Action of this module when the Content Type "Basic Page" is viewed
-The above Rule fires as expected, the File is created and entered into the database as expected, but when the page loads the Title of the page of the View name, not the Node title
-If the above Rule is disabled the page loads with the correct Title
-Other Rules Event cause the same thing to happen
-Attached are screen shots of the page display with the Rule enabled and disabled

Any idea why this is happening? I can send you the login credentials of my test site if you'd like.

Thanks,

Kyle

hanoii’s picture

You found a very very nasty bug, one which I am not sure I'll able to fix in the most flexible way.

The most acceptable way of working this out is by requesting the PDF out of the site through an internal http requests, so that the request is completely independent form the current pdf generation. The reason behind this is that the print module does quite non-standard things for getting the HTML for the pdf generation.

This has one caveat though, and it is that the URL you want to get the pdf from has to be accessible as an anonymous users.

This means that you should be able to get the PDF by visiting http://example.com/printpdf/XXXXX anonymously.

Would this be OK for you? I am afraid I might not find another way of working it out properly for paths. This happens mainly for the node view event. Another possibility is making sure it does work better for other events and prevent the action from running but this is not straightforward either. I had a fatal error though by doing what you did, instead of just the page title issue.

Also bear in mind that per your screenshots, is not that you are seeing a different title, you are seeing the actual 'view' when visiting the node, only that it has that one node.

Will think it through a bit more and have another crack at it tomorrow but let me know if this anonymous thing is enough for you

hanoii’s picture

Ok, after thinking a bit more, I think I could the the fetching but still use the logged in cookie from the browser allowing to use the same authentication of the users triggering the rule, if any. Of course in a case of an anonymous execution of the rule, then the rule will fetch the PDF as anonymous and so it would have to be accessible to anonymous users.

You can try updated code, refresh Rules cache (or reinstall) as I removed the node action altogether, it could be done with the path action anyway and because it's a fetch it makes more sense to having it independent.

hanoii’s picture

Well, today I took another crack at it and continued with the above approach.

I think this module has just evolved into something else, which I think I will call it rules_download or something like that.

I realized with the change above that you no longer need any kind of dependency into the print module, this will work downloading the pdf from your site as well as any other html/file from any other place.

I changed the settings a bit, now you can use an internal drupal path and and external URL, if you want you can now use prinpdf/xxx as you did in the first place as that will get you the pdf, otherwise it will just get you the HTML.

I also added a new setting for sending the cookie to the request, so you can, if you want, use the user logged in access for the URL.

Anyway, I definitely thing this will work for you and now it's a bit far more flexible as before.

I did go a quite a bit over what I had planned time-wise, but it's a nice module nonetheless.

Remember, clear the cache, rules cache and you will have to check the rules setting.

Bear in mind that the when requesting a URL, that request can again lunch this rule. That part is a bit error prone, but I have put some validations to prevent this rule's action to run if requested by this same action, by adding an URL parameter to the request.

cgdrupalkwk’s picture

Hi,

Thanks for making these change. So far this new version is working great! I will continue to test and let you know if I find any other bugs. Is there anything you'd like me to test?

The only thing I found is that it would be helpful to have an Action that uses the "file_create_url" function. This works better than realpath for including links to files within the body of an email and works well if the file storage is outside the root Drupal installation.

Kyle

cgdrupalkwk’s picture

Hi,

I made a patch to add the Action I mentioned above to also get the url of the file using the "file_create_url" function. It works but this is the first patch i've ever created so please excuse me if it's a hot mess. Any feedback would be greatly appreciated.

I think this is working well and haven't found any new bugs of missing features.

Thanks again for your work on this! I'm very happy with the result.

Kyle

  • Commit 2f77282 on 7.x-1.x authored by cgdrupalkwk, committed by hanoii:
    Issue #1434438 by cgdrupalkwk: small patch adding an action for showing...
hanoii’s picture

You can craft that with some PHP on rules, but I was gonna add it, but since you add you gave a patch, and being your first one, I just committed, patch was good! Gave you authorship of the patch, so you can see your first commit in your profile page!

Will now probably change some text, variables and module names and soon release it as a module.

Also I add a mention for your contribution in the project page, let me know if I shall place al link to a company or site of yours or just mention your drupal.org profile.

hanoii’s picture

Also, since it was your first patch, although I have very little to comment, you might want to take a look at https://drupal.org/patch/submit for guidance, look also for the recommended naming conventions.

hanoii’s picture

Status: Needs work » Fixed

Module released as rules_download, you probably need to reinstall and change your own rules. New 1.0 release should be out, please open new issues if you find any new stuff or for any other discussion.

THANKS!

hanoii’s picture

Project: Rules download » Printer, email and PDF versions
Version: » 7.x-2.x-dev

Bringing it back to Print module so it's easier to find for people.

If you need this, it can be accomplished with Rules download.

hanoii’s picture

Issue summary: View changes
hanoii’s picture

Title: Some Print PDF Rules integration (Willing to sponsor advancement of this) » Some Print PDF Rules integration
dromansab’s picture

Hi,

Is this patch still working? I need to send pdfs by email. I've applied it but I'm recieving emails without attachments...

Thanks

cgdrupalkwk’s picture

Hi,

The Rules Download Module in post 36 supercedes this patch and will solve your problem. Let me know if you have questions regarding the configuration of a Rule.

dromansab’s picture

I would greatly appreciate your help.
I've downloaded the module and I don't understand how I can generate and attach the PDF.

This is my rule:

{ "rules_generate_pdf" : {
    "LABEL" : "Generate and send PDF",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "TAGS" : [ "invoice", "teacher" ],
    "REQUIRES" : [ "rules", "rules_download", "mimemail" ],
    "ON" : { "node_update--invoice" : { "bundle" : "invoice" } },
    "IF" : [
      { "data_is" : { "data" : [ "node:field-inovice-status" ], "value" : "ok" } },
      { "entity_has_field" : { "entity" : [ "node:field-student" ], "field" : "field_mail" } }
    ],
    "DO" : [
      { "rules_download_action_generate_path" : {
          "USING" : {
            "path" : "printpdf\/[node:nid]",
            "cookie" : 1,
            "uri_scheme" : "public",
            "temporary" : 1
          },
          "PROVIDE" : { "rules_download_file" : { "rules_download_file" : "Downloaded file" } }
        }
      },
      { "rules_download_action_realpath" : {
          "USING" : { "file" : [ "rules-download-file" ] },
          "PROVIDE" : { "rules_download_file_path" : { "rules_download_file_path" : "File real path" } }
        }
      },
      { "mimemail" : {
          "key" : "invoice_[node:nid]",
          "to" : [ "node:field-student:field-mail" ],
          "subject" : "Factura [node:field-text1]",
          "body" : "Your invoice.",
          "attachments" : "[rules-download-file-path:value]",
          "language" : [ "" ]
        }
      }
    ]
  }
}

Thanks

hanoii’s picture

@dromansab, can you please create a new issue in the rules download module "How to attach a downloaded file to a mail with mimemail?" with your same rules export and we can follow it up there, you can reference it here if you want as well. The answer is pretty simple though but having it there will be better for others to find the answer.

ericwongcm’s picture

For those who are using rules download to email pdf, can you export the rule you are using and post it at rules_download issue tracker https://drupal.org/node/2264671 so others like me can use or modify it for their purpose?

I have no clue how to configure the rule to e-mail pdf...

dromansab’s picture

Ok,
I've created the issue in the rules download module.

Thanks

Status: Fixed » Closed (fixed)

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