Suggested Feature - Article PDF File Name

Phoca PDF - creating PDF documents in Joomla! CMS
big-pete
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 21 Aug 2009, 19:45

Suggested Feature - Article PDF File Name

Post by big-pete »

Currently, the plgSystemPhocaPDFContent plug-in defaults to a PDF filename of 'Phoca PDF' if the plug-in parameter 'PDF Name:' (as set in the back-end component) is left blank. This is set on line 125 of the \plugins\system\phocapdfcontent.php file:

Code: Select all

$content->pdf_name = $pluginP->get('pdf_name', 'Phoca PDF');
While this works I would suggest that it would make more sense for the $content->pdf_name to be set to the title of the article itself IF the 'PDF Name:' parameter is left blank. i.e. An article titled 'My Favorite Things' would get a $content->pdf_name of something like 'my-favorite-things.pdf'. In my case I'd prefer users to download PDF documents with file names that make it somewhat clear (for later recall) what it is.

An additional parameter of 'Use Article Title for File Name' could be included in the backed if that sort of default behavior is not to Phoca's liking. FWIW, I was able to implement this behavior with a simple code change (use at your own risk):

File: \libraries\joomla\document\phocapdf\phocapdf.php
Line: 142
Change:

Code: Select all

switch ($option) {
  case 'com_content':

    $results = $dispatcher->trigger('onBeforeDisplayPDFContent', array (&$pdf, &$content, &$this));

    break;
To:

Code: Select all

switch ($option) {
  case 'com_content':

    $results = $dispatcher->trigger('onBeforeDisplayPDFContent', array (&$pdf, &$content, &$this));
    if($content->pdf_name == 'Phoca PDF') $content->pdf_name = $this->getName();

    break;
NOTE: I've also change the setName function in the \libraries\joomla\document\phocapdf\phocapdf.php to:

Code: Select all

function setName($name = 'Phoca') {
  $this->_name = JString::strtolower(JFile::makeSafe(JString::str_ireplace(' ', '-', $name)));
}
so as to attempt to eliminate any wacky characters that might be in the article Title.

While this may not be the absolute best way to go about it (you guys know your code much better than I do) I think implementing something like this would be quite easy and potentially improve the product. Thanks for listening.

PS: Almost forget: Sticking on a '.pdf' file extension to the $content->pdf_name probably wouldn't hurt as well but not sure it's absolutely necessary.
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Suggested Feature - Article PDF File Name

Post by Jan »

Hi, thank you for this info, the problem can be diacritics in article names, so then it should be alias used (As aliases have problems with diacritics - not correctly translated diacritics). I will take a look at it.

Jan
If you find Phoca extensions useful, please support the project
big-pete
Phoca Newbie
Phoca Newbie
Posts: 2
Joined: 21 Aug 2009, 19:45

Re: Suggested Feature - Article PDF File Name

Post by big-pete »

Jan, no problem. As a side note it seems most joomla components use the following to make safe aliases:

Code: Select all

$this->alias = JFilterOutput::stringURLSafe($this->alias);
In the end changing the setName function to apply this function (as well as any others you feel warranted might be the trick. Good luck and thanks for a great product!

Pete

PS: I've changed my various setName functions to now use the JFilterOutput::stringURLSafe method instead of what I posted earlier. Eat my own dog food so to speak. :wink:
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Suggested Feature - Article PDF File Name

Post by Jan »

Hi, there is a problem with the $this->getName(), It seems like the name is not allways loaded, so then the name is empty. So because of it the "Phoca PDF" name is added instead of empty name :(
If you find Phoca extensions useful, please support the project
motofzr1000
Phoca Newbie
Phoca Newbie
Posts: 4
Joined: 29 Apr 2011, 23:18

Re: Suggested Feature - Article PDF File Name

Post by motofzr1000 »

Hi,

I've implemented this code, and it seems to work.
However, it only works for me with the direct download option enabled.
When I open the pdf in a popup window, and try to save the pdf, it's called index.pdf, and not the article title.
Is there a way to get this to work with a popup window also?
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Suggested Feature - Article PDF File Name

Post by Jan »

Hi, index.php is set by the PDF plugin in OS, this cannot be changed :-(

Jan
If you find Phoca extensions useful, please support the project
hamss
Phoca Newbie
Phoca Newbie
Posts: 5
Joined: 16 Nov 2012, 00:14

Re: Suggested Feature - Article PDF File Name

Post by hamss »

Hi,

there is no \libraries\joomla\document\phocapdf\phocapdf.php in J2.5 / PhocaPDF 2.0.7 any more.
Is there any possibility to implement this to the new one?

I would be greateful if sb could help me.
Regards
User avatar
Jan
Phoca Hero
Phoca Hero
Posts: 48403
Joined: 10 Nov 2007, 18:23
Location: Czech Republic
Contact:

Re: Suggested Feature - Article PDF File Name

Post by Jan »

Hi, then just ftp it again (get in the installation ZIP file)

Jan
If you find Phoca extensions useful, please support the project
Post Reply