I'm a bit confused with this module. Looks like I can only create a PDF file with one name.
If I keep "PDF filename" field empty, I get TCPDF ERROR: Unable to create output file: /var/aegir/platforms/drupal-8.6.0/node_108_printable_pdf.pdf -error. I suppose it has something to do with permissions. Therefore I use folder sites/default/csv which has right permissions.
With this method I have to put a fixed filename after the folder path, like this sites/default/csv/testfile.pdf.
This generates the pdf but now every page uses this same file :-(
Is there a Token support or how can I change the filename dynamically...?
Comments
Comment #2
nigelcunningham commentedComment #3
aperedos commentedThis patch allow to create some tokens for filename field.
Comment #4
rd.michael commentedaperedos thanks for the patch. It almost worked for me, but I really needed the node tokens and your syntax isn't quite right for that. For "all" it shouldn't be in an array, it should be
'#tokens_type' => 'all'. However, that produces a ton of possible tokens, most of which probably aren't needed. I think a better solution would be to just use the "node" tokens. i.e.'#token_types' => [ 'node' ]. This is how the Drupal 7 print module handles it too https://git.drupalcode.org/project/print/blob/7.x-2.x/print_pdf/lib_hand....After adding that the browse available tokens link works for me as it shows the "nodes" options for token replacement. However, even after using one, such as [node:title] it doesn't get replaced in the output. I believe the context is somehow wrong, because when I use the token [current-page:title] it outputs "Printable", the title of the module, rather than the title of the front-end page. I'm not sure how to fix this issue.
Comment #5
rd.michael commentedAh I figured it out. We need to pass in the node as context to the
$token_service. If you replace line 299 of PdfFormat.php with this it will work (in addition to the above comment).Comment #6
sethhill commentedAdding code from comment #5 into the previous patch.
Comment #7
nigelcunningham commentedThanks for the patch, everyone - and apologies for my lack of attention to the project. I'll seek to get it in better shape, including reviewing and applying this patch.
Comment #9
nigelcunningham commentedThanks for the work on this. I've just committed a version with some additional changes so it's not node centric. Note though that this is only a temporary file (or supposed to be) so we're mainly just avoiding collisions if multiple users request a download at the same time - the filename itself shouldn't matter too much.