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!

#9 changing-output-name-1722492-9.patch473 byteskillua99


Simon Georges’s picture

Version: 7.x-1.0-rc1 » 7.x-1.x-dev
Component: Code » Miscellaneous
Category: task » support
krios’s picture

Ah thanks for changing to the correct category. Can anyone offer any direction? :/

hessam61’s picture

Is there any update on this? I'd like to alter the file name as well. Currently it's using Views' machine name.

s.Daniel’s picture

Component: Miscellaneous » Code
Category: support » feature

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

hockey2112’s picture

I am interested in this as well.

vegansupreme’s picture

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


2) In views_pdf_plugin_display.inc, change

if (empty($path_to_store_pdf)) {
      $path_to_store_pdf = $this->view->name;


if (empty($path_to_store_pdf)) {
      $path_to_store_pdf = $this->view->build_info['title'];

I haven't tried this second way yet.

killua99’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: +Needs steps to reproduce

Dear 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

ufku’s picture

Status: Postponed (maintainer needs more info) » Active

People just want a way to set the PDF name dynamically.

And this is possible if you change
$path_to_store_pdf = $this->view->name;
$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.

killua99’s picture

Status: Active » Needs review
Issue tags: -Needs steps to reproduce
473 bytes

This is a feature that can be easily introduced.

Please need reviews this patch, but I did a push into the dev branch.

vegansupreme’s picture

Works for me

killua99’s picture

Issue summary: View changes
Status: Needs review » Closed (fixed)
Makku01’s picture

Status: Closed (fixed) » Active

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

killua99’s picture

Ok, so I need this kind of feedback :)

What you want is a even more custom field for the title?

Makku01’s picture

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

Makku01’s picture

Okay, this is how i've done it. Quite hacky, I know but for me it works! Thanks a lot for this awesome module!

    if (empty($path_to_store_pdf)) {
		$arg = $this->view->args[0];
		if(is_numeric($arg)) $node = node_load($arg);
		$title = isset($node) ? $node->title : $this->view->get_title();
		$path_to_store_pdf = $title;
killua99’s picture

If you want a stable fix, bring me a patch! yaaarggg!!

vegansupreme’s picture

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

killua99’s picture

So this doesn't make sense ?? I'll close it then ...

lindaweb’s picture

How do i add a node create date stamp to : $path_to_store_pdf = $this->view->get_title(); ?

killua99’s picture

Status: Active » Needs work

No idea @lindaweb

Should we keep this issue?

asif_khan’s picture

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

vegansupreme’s picture

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

killua99’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Issue tags: +views_pdf_7.x-2.x

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