I've set PDF file name to:
[title] - [site-name] - [mod-yyyy]-[mod-mm]-[mod-dd]

For the front page (where more node summaries are published), [mod-yyyy], [mod-mm] and [mod-dd] are obviously not set, and the PDF file name becomes something like:
Example Title - www.example.com - [mod-yyyy]-[mod-mm]-[mod-dd].pdf

This looks not only ugly, but also not very professional. It would therfore be good the name composition to work in a bit more clever way, for example to skip some parts if all components of it (or, if any component) are missing (not set). In my particular example, I would like to check if [mod-yyyy] is not available, and skip the complete " - [mod-yyyy]-[mod-mm]-[mod-dd]" part in such a case.

As it is probably not easy to hard code all possible situations to suit any needs, a possibility to add a PHP code instead of just a text field (and, then replace tags as [mod-yyyy] with appropriate variables before processing it...) would be an optimal solution (altough not very user-friendly for people without any programming skills...).

So, in my case, something like:
"[title] - [site-name]" . !isset([mod-yyyy]) ? " - [mod-yyyy]-[mod-mm]-[mod-dd]" : ""
could be used...

Or, use conditional fields (one field for condition and other 2 for TRUE / FALSE case) to be concatenated, to get the complex file name. This would make it a bit easier for users not know much about PHP (altough any site admin should probably be able to make a conditional sentence in PHP).

Comments

jcnventura’s picture

That's all handled by the token module. Of course, those tokens are only set for nodes... I will try to filter everything between [] for non-nodes..

Apfel007’s picture

subscribe

Apfel007’s picture

any ideas on that?
How could be manage this issue?

Apfel007’s picture

any news?

Ashraf Amayreh’s picture

Category: support » bug

I think this amounts to a bug, as far as I can tell, this also fails (this is a webform generated URL to generate PDFs from submissions):

http://www.example.com/printpdf/131/submission/99

This also has no access to node variables at all. What I'm a little unsure about is weather this is a token or print module issue. If someone can point me to where this is handled I'll be glad to submit a patch.

pillarsdotnet’s picture

I'd vote for "token issue" but maybe there is someone out there who wants square-brackets in their otherwise token-replaced strings. See for example #733192: Tokens enclosed in [ ] are not recognized

Ashraf Amayreh’s picture

Version: 6.x-1.12 » 6.x-1.x-dev
Assigned: Unassigned » Ashraf Amayreh
Status: Active » Reviewed & tested by the community
StatusFileSize
new762 bytes

Well, it turns out this one in particular is a print module issue.

The node, which is passed to tokens was undefined. All I needed was to load it before the call to token_replace(). Patch attached.

Ashraf Amayreh’s picture

Assigned: Ashraf Amayreh » Unassigned

Oh, I think it's wrong to assign it to myself... unassigning...

jcnventura’s picture

Status: Reviewed & tested by the community » Needs review

I need to see this better.. If this were the solution, tokens would never have worked.

luti’s picture

Patch in #7 doesn't seem to resolve my issue (tested with the front page). And, yes - I've cleaned the cache (Drupal and browser), if it matters.

pillarsdotnet’s picture

StatusFileSize
new1.36 KB

Calls to token_replace() should be setting the clear option.

Patch attached.

jcnventura’s picture

@pillarsdotnet: that would be for the D7 version right?

pillarsdotnet’s picture

StatusFileSize
new1.43 KB

Yes, but the same syntax is used in the 6.x-1.x version of the token module.

6.x-compatible patch attached.

luti’s picture

Unfortunately, patch #13 doesn't seem to resolve my issue either (at least at the frontpage I've tested).

jcnventura’s picture

@LUTi: I think you have to be using the current dev of token module for that patch to be effective (I still haven't tested this)

luti’s picture

I've installed print -dev and token -dev version, but now I am even without a [title] (it is replaced by an empty string). I've tried also [page-title] and [current-page-title] - they are both replaced by "PrinterFriendly PDF" instead of the original page title.

Reverting token back to 1.15 didn't resolve anything, so I can only blame the new -dev version of PrintPDF for even worse behavior. Fortunately, my production site is still using the old configuration.

2ndmile’s picture

I am getting blank file names when using [title] as well. Any progress on this issue?

Anonymous’s picture

same problem of #17, any progress about this issue?

Anonymous’s picture

Status: Needs review » Needs work
jcnventura’s picture

Status: Needs work » Needs review
Anonymous’s picture

I updated the print module to last dev but the issue is still present

[site-name]_[title]_[mod-small]_by_[author-name]
gives
site-name_title_mod-small_by_author-name

I also tryed to apply patch #13, but it doesn't work

jcnventura’s picture

Status: Needs review » Fixed

This problem was introduced as part of splitting the print_pdf_controller() function in order to provide an API for PDF generation (#1044138: Allow print_pdf to be called from another module and return PDF as a string (eg to attach a PDF with mimemail)).

I've fixed this in D7 and D6.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jvieille’s picture

Not sure it is the same issue, but using print-6.x-1.14 or the last dev generates a pdf name like this
book_export_html_165.pdf

where 165 is the node ID

Note:
- pdf file name is set to default "[site-name] - [title] - [mod-yyyy]-[mod-mm]-[mod-dd]"
- using tcpdf

bachbach’s picture

StatusFileSize
new1012 bytes

here is my "not super clean" solution.
on print_pdf.pages.inc L35, replace

 elseif (ctype_digit($args[0])) {
    // normal nid
    $node = node_load($args[0]);
  }

by

	elseif($item = menu_get_item($path)){
		if($item['page_callback'] == 'book_export'){
			// get the node from book export arguments
			$node = node_load($item['page_arguments'][1]);
		}elseif (ctype_digit($args[0])) {
    	// normal nid
	    $node = node_load($args[0]);
	  }
	}

jvieille’s picture

patch #25 works fine.
18 months issue, please commit!

Thanks

bfdi533’s picture

This patch works for me as well. Please commit.

kholloway’s picture

FYI, Patch #25 worked for me as well using the Drupal 6 latest Dev version.