Closed (outdated)
Project:
FillPDF
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
12 Feb 2012 at 15:19 UTC
Updated:
29 May 2025 at 14:40 UTC
Jump to comment: Most recent
Comments
Comment #1
wizonesolutionsWe currently don't yet have a
fillpdf.api.phpfile, though we should. That said, you simply implementhook_fillpdf_merge_pdf_fields_alter(&$fields, $context);and change the fields as needed. Your modified values will be placed into the PDF. Note that this happens after field transformations (as configured in the UI) have occurred.Fields are indexed by PDF key. The value is the array element value.
$contextcontains'nodes'and'webforms', which contain loaded nodes and webforms corresponding to the Fill PDF URL. There won't be any webforms in there if you aren't filling a webform, and the nodes will correspond to the webform node if you are.So here is an example. Untested but gives a starting point:
Does this help?
Also changing this to a task to document this hook.
Comment #2
bjalford commentedperfect - thanks
Comment #3
wizonesolutionsNeed to create
fillpdf.api.phpand document the other hooks as well.Comment #4
wizonesolutionsComment #5
kiricou commentedI try to do the same thing, I create a function
in my own module named form_template which contain other functions which work.
Nothing different when FillPDF generate the PDF.
When I put this line
just under the
in FillPDF module, it works.
I uninstall and reinstall my module but nothing.
Any idea for debugging?
drupal 7.22
FillPDF 7.x-1.9
Thanks
Comment #6
wizonesolutionsIs your module named
form_tempalte? Try clearing the cache. Your function signature looks correct. Doing it in your module should work as well, particularly if it works there.Comment #7
kiricou commentedYes, the name of the module is correct others hooks work.
But I work with Fill PDF 7.x-1.9, maybe it's better with dev version ?
Thanks
Comment #8
kiricou commentedif I rename my function :
function form_template_fillpdf_merge_fields_alter_alter(&$fields, $context) {
two times _alter
it works !!
i don't know why... but it works
Comment #9
kiricou commentedI need to add new line in the field I alter, how to do that ?
Like "Line 1\nLine2" ...
Thanks
Simon
Comment #10
wizonesolutionsAh. You're right about the function signature. That's not what I intended, but that is currently the right way to do it.
To add a new line, trying adding
<br>or<br />to the output. There is code somewhere infillpdf_merge_pdfthat replaces it with newlines.Comment #11
kiricou commentedThank you but
'<br />'does not work.To add a new line, simply
and the form field has to support multi line !
Comment #12
Anonymous (not verified) commentedThe row should be drupal_alter('fillpdf_merge_fields', $fields, $context,$fillpdf_info); in the file fillpdf.module.
Alter will be concatenated in the drupal_alter function. The additional fillpdf_info gives the possibility to check which pdf-template you are using.
Can be checked like this:
if(endswith($fillpdf_info->url,'Invoice_Template.pdf'))
Comment #13
wizonesolutionsfilantrop: Yes, I said that in comment #10 :)
Patch welcome in a separate issue to fix the callback name. It can be changed completely in 7.x-2.x, but the correct version can only be added as an alias for the current version in 7.x-1.x (can't break the API in 7.x-1.x). Thanks.
Thanks for the comments and usage examples! If you want to put these in the Fill PDF documentation, you are welcome. Everyone can edit documentation.
Comment #14
oenie commentedI encountered the same problem, added a patch in #2140435: Confusing hook name 'hook_fillpdf_merge_fields_alter_alter'.
Comment #15
liam morlandComment #16
liam morlandComment #17
allahnoor turab commentedFor me it is not working with drupal version 9.5.2 and fillpdf version 5.0
I not see any output.
I want this hook to remove prefix and change date format for some fields
/**
* Implements hook_fillpdf_merge_fields_alter().
*/
function miscellaneous_fillpdf_merge_fields_alter(&$fields, $context) {
dump($fields);
// $submission = end($webforms); // Gets the last sid passed.
// $ticket_price = 5.00; // @todo: Replace with code to get this from the webform object.
// $fields['The rent is'] *= $ticket_price; // Multiply number of guests by ticket price.
}
Comment #18
liam morlandI thought
dump()was a Twig function. It won't work in a hook implementation. Ifdevelmodule is enabled, you should be able to usedpm().Comment #19
allahnoor turab commentedNo success, actually the hook is not triggering.
Comment #20
liam morlandhook_fillpdf_merge_fields_alter()only exists in Drupal 7.Comment #21
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.