Path not ending in .pdf

Created on 16 January 2016, over 9 years ago
Updated 20 June 2025, about 1 month ago

Hello, since I want the path to the pdf to end in .pdf I had to do several things which I explain here so you can do the same if you want :
- create a rule in .htaccess
RewriteRule ^ebook-(.+)_(.+).pdf$ /index.php?q=node/$2/pdf [NC,QSA,L]

- create a block to display only on nodetype's pages, in php :

<?php
if ($node = menu_get_object()) {
  $nid = $node->nid;
 $ntitle = $node->title;
 $npath = drupal_get_path_alias("node/".$nid);
}
$nfullpath = 'ebook-'.$npath.'_'.$nid.'.pdf';
echo '<div style="text-align:center;"><a href="/'.$nfullpath.'" title="'.$ntitle.'"><img src="/path/to/pdfdownload.png" width="128" height="128" alt="'.$ntitle.'" /></a></div>';
?>

- in the module settings I use this for the filename :
ebook-[node:url:alias]_[node:nid]

- in order to stop display the "Generate PDF" link above the content, one line needs to be changed in the module :
line 61 instead of
'type' => MENU_LOCAL_TASK,
I write
'type' => MENU_CALLBACK,

so that at the end :
on my articles, I have a block showing a PDF DOWNLOAD image link which links to the nice path of the pdf file
ebook-keywords-here_nodeID.pdf
which .htaccess redirects to /index.php?q=node/nodeID/pdf
so the PDF file is created and in the http headers the filename of the PDF is still the same

At the end it really looks like the PDF file is a real one, not an auto-generated one.

Hope it helps someone using this nice module.

Feature request
Status

Closed: outdated

Version

2.6

Component

User interface

Created by

🇹🇭Thailand alliax

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024