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.
I would like to alter the output of the pdf filename. After digging around views_pdf_plugin_display.inc, it seems the output is using the view machine name?
if (empty($path_to_store_pdf)) {
$path_to_store_pdf = $this->view->name;
}
How do I reference a field in the view, such as content title, so I can append it to the output? I understand some formatting would be required to make it a valid filename.
I am a novice with PHP, so any help/direction is greatly appreciated!
Comment | File | Size | Author |
---|---|---|---|
#9 | changing-output-name-1722492-9.patch | 473 bytes | killua99 |
Comments
Comment #1
Simon Georges CreditAttribution: Simon Georges commentedComment #2
krios CreditAttribution: krios commentedAh thanks for changing to the correct category. Can anyone offer any direction? :/
Comment #3
hessam61 CreditAttribution: hessam61 commentedIs there any update on this? I'd like to alter the file name as well. Currently it's using Views' machine name.
Comment #4
s.Daniel CreditAttribution: s.Daniel commentedSince clearly this issn't possible currently and the request could be usefull I'm changing this to feature request.
Basically a new setting for "PDF SETTINGS" is requested that makes it possible to set a custom file name, preferable with the support of tokens.
Comment #5
hockey2112 CreditAttribution: hockey2112 commentedI am interested in this as well.
Comment #6
vegansupreme CreditAttribution: vegansupreme commentedI found at least one way to alter the PDF filename.
1) Add this to the last "PHP Code After Output" box
$this->view->pdf->Output("YOUR PDF NAME");
This should go at the very end of any code. As far as I can tell, nothing after it will be rendered.
You could change out "YOUR PDF NAME" to something like
$this->view->build_info['title']
to use the view title.-OR-
2) In views_pdf_plugin_display.inc, change
to
I haven't tried this second way yet.
Comment #7
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 #8
ufku CreditAttribution: ufku commentedPeople just want a way to set the PDF name dynamically.
And this is possible if you change
$path_to_store_pdf = $this->view->name;
to
$path_to_store_pdf = $this->view->get_title();
in views_pdf_plugin_display.inc
The title can include field placeholders or can be set by contextual filters, which is how people would be able to change the PDF name.
Sorry for not proving a patch but the change is pretty simple to apply and I don't think it will break anything.
Comment #9
killua99 CreditAttribution: killua99 commentedThis is a feature that can be easily introduced.
Please need reviews this patch, but I did a push into the dev branch.
Comment #10
vegansupreme CreditAttribution: vegansupreme commentedWorks for me
Comment #11
killua99 CreditAttribution: killua99 commentedComment #12
Makku01 CreditAttribution: Makku01 commentedSorry guys - the original question was whether it's possible to appand a field value as title. Here we just changed from "machine name" to "title". Thats not quite what the opener wanted.
Comment #13
killua99 CreditAttribution: killua99 commentedOk, so I need this kind of feedback :)
What you want is a even more custom field for the title?
Comment #14
Makku01 CreditAttribution: Makku01 commentedYes, in my case I'm using this module for printing out a single node. So it would be cool to make one field of the node the filename. But as I think of it, I come to the conclusion that this won't be suitable for usual usecases where you print a list of different nodes. Maybe you can get the filename out of the argument (when present) such as nodetitle when it's a node or term name when it's a taxonomy term...
Comment #15
Makku01 CreditAttribution: Makku01 commentedOkay, this is how i've done it. Quite hacky, I know but for me it works! Thanks a lot for this awesome module!
Comment #16
killua99 CreditAttribution: killua99 commentedIf you want a stable fix, bring me a patch! yaaarggg!!
Comment #17
vegansupreme CreditAttribution: vegansupreme commentedMakku01, You're right, for the majority of use cases I don't think it would make sense to use an individual field value for filename. If you're showing a single node, just use contextual filter > override title: "%1". That should make the node title be the view title, and therefore the PDF filename.
While it's true you wouldn't be able to use any field as a filename, node title and taxonomy terms would be easy to do.
Comment #18
killua99 CreditAttribution: killua99 commentedSo this doesn't make sense ?? I'll close it then ...
Comment #19
lindaweb CreditAttribution: lindaweb commentedHow do i add a node create date stamp to : $path_to_store_pdf = $this->view->get_title(); ?
Comment #20
killua99 CreditAttribution: killua99 commentedNo idea @lindaweb
Should we keep this issue?
Comment #21
asif_khan CreditAttribution: asif_khan commentedthis would be great feature because pdf custom file name is what most of time needed. and it should be as customize as "views". i am not a developer but i think we should add a field like "pdf:filename" like pdf:pagebreak. it just a suggestion.
thanks
Comment #22
vegansupreme CreditAttribution: vegansupreme commentedThis seems to be a pretty popular request. Maybe for v2?
interesting idea @asif_khan about implementing as a field handler. I hadn't thought about how to implement this.
I could see the usefulness, even for multi-row views, where all nodes share a taxonomy term, for example.
Comment #23
killua99 CreditAttribution: killua99 commentedAlright, we should push it to V2 then ....
So be ware, this will not be included on the V1 you might wait for the next version. The next version will be done when is ready, like Drupal 8.
Regards