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.

Comments

wizonesolutions’s picture

It'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().

wizonesolutions’s picture

Version: 6.x-1.15 » 7.x-1.x-dev

New features happen in 7.x first now.

wizonesolutions’s picture

Title: Integration with Triggered Actions » Rules integration
Issue tags: +rules integration

Changing the title to what this really is.

wizonesolutions’s picture

OK, 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, flatten or download could be changed.

Fill PDF is ready to fill the PDF

Tokens have now been replaced, and $fillpdf contains 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 $fillpdf data 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.

wizonesolutions’s picture

Issue summary: View changes

Triggered Actions to Rules. I meant Rules

wizonesolutions’s picture

Issue summary: View changes

Added spec to issue summary

wizonesolutions’s picture

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

wizonesolutions’s picture

Issue summary: View changes

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

wizonesolutions’s picture

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

wizonesolutions’s picture

Issue summary: View changes

Fleshed out default rules section according to comment.

wizonesolutions’s picture

Updated 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!

wizonesolutions’s picture

Status: Active » Needs review
StatusFileSize
new21.58 KB

And, 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.

wizonesolutions’s picture

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

wizonesolutions’s picture

StatusFileSize
new499 bytes

I broke the module if Rules isn't enabled, so this patch fixes it. Badly-placed but already pushed.

wizonesolutions’s picture

Tagging to be worked on during the camp.

wizonesolutions’s picture

Issue tags: +fillpdf2

Tackle this in refactor.

tslifset’s picture

Is it possible to use tokens for "Webform Submission ID(s)" in the exposed rule action

"Fill a PDF with webform data"

?

wizonesolutions’s picture

Yeah. You probably need the Webform Rules patch mentioned in the documentation.

penone’s picture

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

silkogelman’s picture

Title: Rules integration » Fill PDF Rules integration
wizonesolutions’s picture

Title: Fill PDF Rules integration » Rules integration

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

penone’s picture

StatusFileSize
new18.05 KB

This is the section I am speaking of.

wizonesolutions’s picture

No, 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.

Bharat13’s picture

Hi,
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.

wizonesolutions’s picture

Can you open a separate feature request or support request for this?

Bharat13’s picture

Sure.

wizonesolutions’s picture

Status: Needs review » Closed (fixed)

This has been in for a really long time. Time to close it and deal with anything related as a follow-up.

wizonesolutions’s picture

Issue summary: View changes

Updated the status of each part of Rules integration.

  • Commit 6ae9152 on 7.x-1.x, 7.x-2.x, 7.x-2.x-tests1, 7.x-1.x-ubercartbackporttest by wizonesolutions:
    Issue #1266174: Make sure Rules is enabled.
    
  • Commit da2ae5d on 7.x-1.x, 7.x-2.x, 7.x-2.x-tests1, 7.x-1.x-ubercartbackporttest by wizonesolutions:
    Issue #1266174: Add hook_fillpdf_merge_pre_handle().
    
    
  • Commit f410029 on 7.x-1.x, 7.x-2.x, 7.x-2.x-tests1, 7.x-1.x-ubercartbackporttest by wizonesolutions:
    Issue #1266174: Add enough Rules integration for e-mail attachment.
    
    Way...
liam morland’s picture

Issue tags: -fillpdf2