Goal: Provide more flexibility to third-party modules and site builders to both trigger Fill PDF programmatically and to react to Fill PDF being triggered and modify the data in the PDF and potentially perform other actions.
Rules works by defining Events, Conditions, and Actions. Data types also need to be provided, and it's capable of intelligent saving.
Data type
[done] Fill PDF fields (simply fillpdf if a machine name is required. Should contain the Fill PDF fields in a sensible state, according to the event, indexed by PDF key. Intelligent saving should work in the sense that several Rules actions should be able to work together. Nothing is actually saved, so I'm not sure if it's relevant. However, the data should be alterable when responding to actions where this makes sense.
Events
Fill PDF is about to prepare PDF-filling data
fillpdf_merge_pdf() has been called, but tokens have not yet been replaced. Changes can be made to processing behavior at this stage; for example, flatten or download could be changed.
Fill PDF is ready to fill the PDF
Tokens have now been replaced, and the fillpdf data array contains the replaced values. They can be modified prior to being merged into the PDF.
Filled PDF is about to be handled
[done] The PDF has been filled, and the file contents are available. This event is most likely to be used when trying to send the PDF as an attachment.
Conditions
A node is being filled
A Webform is being filled
These are just as they sound. They aren't strictly necessary because it's possible to just to check if one or the other is empty in the data array. However, these are such common things to check that they merit their own conditions. Things like whether flatten and download are set, on the other hand, can begin just as properties of the fillpdf data array.
All other necessary data will be provided in the fillpdf data array, including metadata such as URL arguments. Rules's built-in conditions should be able to provide a great deal of additional flexibility from there.
Actions
Fill a PDF with content data
This would be like going to a Fill PDF link, but the work would be done programmatically via Rules. This action would create a variable with the contents of the filled PDF.
Fill a PDF with webform data
[done] This would be like going to a Fill PDF link, but the work would be done programmatically via Rules. This action would create a variable with the contents of the filled PDF.
Send PDF to user's browser
Would require a variable created with the previous action. Does what the name says.
Load a Fill PDF configuration
[done] Just as it sounds - given an fid, it creates a Rules variable containing information on that PDF. That can then be fed to Fill a PDF with webform/content data to get fleshed out with the rest of the info.
Save PDF to a file
[done] Like the prior action, but saving to a file. The file path could be overridden; otherwise, metadata in the configured variable would be used to discover the path. The file would be placed in file_prefix://fillpdf if none was set.
Perform the default action on the PDF
[done, needs testing] This would behave like going to the Fill PDF link and do whatever was configured, downloading or saving to a path (if configured).
Default rules
[done for webform] I intend to have a default rule to enable sending a filled PDF as an e-mail attachment. That's pretty much what prompted Rules integration.
Attaching the PDF to an e-mail will require the Mime Mail module. It has both Rules integration and this functionality. The default rule I created also needs Webform Rules.
It will be necessary to use the "Save PDF to a file" action first to get a file path and then to feed this argument to the "Send HTML e-mail" action from Mime Mail, probably using the data selector mode.
In fact, to that end, "Save PDF to a file" will also need to provide a new variable containing the saved file path (already run through drupal_realpath()) and in whatever format Mime Mail is expecting...which isn't entirely clear yet, but I'll figure it out.
------
Original post by landing:
Would it be possible to integrate this module with Rules. I would like to fill a pdf template with node values once a node is created.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | PathToSavedPdf.png | 18.05 KB | penone |
| #10 | fillpdf.rules_module_exists_1266174_10.patch | 499 bytes | wizonesolutions |
| #8 | fillpdf.add_rules_1266174_7.patch | 21.58 KB | wizonesolutions |
Comments
Comment #1
wizonesolutionsIt'd be with Rules, not Actions, but yes, this is a good idea. It won't necessarily happen in short order, although patches to get it started are welcome. Rules are quite easy to implement - start at http://drupal.org/node/878718 - and the function you'd want to wrap or call is most likely fillpdf_merge_pdf().
Comment #2
wizonesolutionsNew features happen in 7.x first now.
Comment #3
wizonesolutionsChanging the title to what this really is.
Comment #4
wizonesolutionsOK, so I'm going to try implementing this. Here is the spec I'll work against:
Goal: Provide more flexibility to third-party modules and site builders to both trigger Fill PDF programmatically and to react to Fill PDF being triggered and modify the data in the PDF and potentially perform other actions.
Rules works by defining Events, Conditions, and Actions. Data types also need to be provided, and it's capable of intelligent saving.
Data type
Fill PDF fields (simply fillpdf if a machine name is required. Should contain the Fill PDF fields in a sensible state, according to the event, indexed by PDF key. Intelligent saving should work in the sense that several Rules actions should be able to work together. Nothing is actually saved, so I'm not sure if it's relevant. However, the data should be alterable when responding to actions where this makes sense.
Events
Fill PDF is about to prepare PDF-filling data
fillpdf_merge_pdf()has been called, but tokens have not yet been replaced. Changes can be made to processing behavior at this stage; for example,flattenordownloadcould be changed.Fill PDF is ready to fill the PDF
Tokens have now been replaced, and
$fillpdfcontains the replaced values. They can be modified prior to being merged into the PDF.Fill PDF has filled the PDF
The PDF has been filled, and the file contents are available. This event is most likely to be used when trying to send the PDF as an attachment.
Conditions
None I can think of. All necessary data will be provided in the
$fillpdfdata array, including metadata such as URL arguments. Rules's built-in conditions should be able to provide a great deal of flexibility from there.Actions
Fill a PDF
This would be like going to a Fill PDF link, but the work would be done programmatically via Rules. This action would create a variable with the contents of the filled PDF.
Send PDF to user's browser
Would require a variable created with the previous action. Does what the name says.
Save PDF to a file
Like the prior action, but saving to a file. The file path could be overridden; otherwise, metadata in the configured variable would be used to discover the path. The file would be placed in file_prefix://fillpdf if none was set.
Perform the default action on the PDF
This would behave like going to the Fill PDF link and do whatever was configured, downloading or saving to a path (if configured).
Default rules
I intend to have a default rule to enable sending a filled PDF as an e-mail attachment. That's pretty much what prompted Rules integration.
There are likely incorrect assumptions in this spec, but it is a conceptual start. I'm going to copy it to the issue summary and will update that as the work goes on.
Comment #4.0
wizonesolutionsTriggered Actions to Rules. I meant Rules
Comment #4.1
wizonesolutionsAdded spec to issue summary
Comment #5
wizonesolutionsUpdated the issue summary - there will be a couple conditions. Also (I will update it with this now), attaching the PDF to an e-mail is going to require the Mime Mail module. It has both Rules integration and this functionality.
It will be necessary to use the "Save PDF to a file" action first to get a file path and then to feed this argument to the "Send HTML e-mail" action from Mime Mail, probably using the data selector.
In fact, to that end, "Save PDF to a file" also needs to provide a new variable containing the saved file path (already run through drupal_realpath()) and in whatever format Mime Mail is expecting...which isn't entirely clear, but I'll figure it out.
Comment #5.0
wizonesolutionsRealized that I at least need the "filling a node" and "filling a webform" conditions in case people want to send e-mails based on the "Filled PDF is about to be handled" event.
Comment #6
wizonesolutionsAaaaalmost have something to commit on this. Just putting the final touches on the default rule.
I wound up implementing more than planned along the way (it was necessary), so even the unfinished verson of the integration is going to open a lot of possibilities. Can't wait.
Comment #6.0
wizonesolutionsFleshed out default rules section according to comment.
Comment #7
wizonesolutionsUpdated the issue summary with what I've finished. About to post the patch and also commit the work to 7.x-1.x-dev. Fasten your seatbelts and get ready to test!
Comment #8
wizonesolutionsAnd, the patch, which is already committed. Applies cleanly against today's dev. It probably does not do the same on the official release, but the more help I get testing, the faster I will make a new release. I don't want to launch this into the wild untested by anyone but myself.
This will be in the -dev version soon. Basically, turn on the rule, change the Webform IDs and fid to yours, and go wild. Patches welcome to help round out the rest of the functionality. Notably, some of the actions need to be finished. I am also thinking that there needs to be a better way to map PDF forms to content and webforms - having to manually specify the Webform ID each time isn't going to fly...however, there are plenty of ways to get creative with that and create a rule that's dynamic, so maybe it's not such a big deal. I wanted to make a default rule that wasn't a far cry from simply getting something working.
You'll need Webform Rules for it, and you will want to apply the patch from #1371278: Join forces with Webform Tokens if you use Webform Tokens until it is committed. This will be documented on the Fill PDF project page soon.
Comment #9
wizonesolutionsA caveat with the default rule is that the latest patch from #1371278: Join forces with Webform Tokens needs to be applied to Webform Rules 7.x-1.3. Need to document this if it's not committed by the time this feature goes into an official release.
Comment #10
wizonesolutionsI broke the module if Rules isn't enabled, so this patch fixes it. Badly-placed but already pushed.
Comment #11
wizonesolutionsTagging to be worked on during the camp.
Comment #12
wizonesolutionsTackle this in refactor.
Comment #13
tslifset commentedIs it possible to use tokens for "Webform Submission ID(s)" in the exposed rule action
"Fill a PDF with webform data"
?
Comment #14
wizonesolutionsYeah. You probably need the Webform Rules patch mentioned in the documentation.
Comment #15
penone commentedFor the life of me I cannot get the Saved PDF To A File rule to work.
I am assuming under Variable Name i am supposed to show the path where i want my file to save to but am not sure how this works. The default is showing as fillpdf_saved_file_path. I assume that the default file path is sites/default/files and then you show the folder that you want to download the pdf into. In my case the folder name is solpar. How do I have the pdf save to this folder? Do I show just solpar?
Thanks for any help.
Comment #16
silkogelman commentedComment #17
wizonesolutionsThis is the Fill PDF module. Redundancy unneeded.
penone: Attach screenshot. Will make it much easier to answer. Relative paths wind up under
sites/default/files, yes.Comment #18
penone commentedThis is the section I am speaking of.
Comment #19
wizonesolutionsNo, that is just adding a new variable. You then have to set the variable to a value, which would be the path you want to save it to. Finally, you pass that value to the "Save PDF to a file" action.
Comment #20
Bharat13 commentedHi,
Is it possible to share pdfs with other user without the use of mail. I would like implement fillpdf wherein users can share PDF with another online user.
Can I use rules for my requirement.
Comment #21
wizonesolutionsCan you open a separate feature request or support request for this?
Comment #22
Bharat13 commentedSure.
Comment #23
wizonesolutionsThis has been in for a really long time. Time to close it and deal with anything related as a follow-up.
Comment #23.0
wizonesolutionsUpdated the status of each part of Rules integration.
Comment #25
liam morland