PDF Resource - dynamic filename generation

I’ve successfully used PDF Resource from @jako for invoice generation, although some questions popped up. When the user tries to download the PDF, the filename is the same as the alias. I guess the code below deals with this:

I want to achieve predetermined filenames, like invoice_20230001_CLIENTID.pdf, is this doable with the extra out of the box?

Do you use live_pdf to generate the PDFs on the fly?


Maybe you could replace the default PDFResource plugin with a custom plugin, that changes the alias of the current resource before createPDF() is called.

But it’s probably cleaner to create your own custom extra based on the code of PDFResource.

Yep, I’m using live_pdf. I was almost certain I did this somewhere in and old project, but I guess I mixed something up. Thanks!

You just have to create a new plugin that runs before PDFResource in OnWebPagePrerender. This plugin has to execute $modx->resource->set(‘alias’, ‘invoice_20230001_CLIENTID’) to set the alias on the fly (it should work even without saving $modx->resource).

1 Like

Sweet, this worked like a charm! Thanks for this!

This topic was automatically closed 2 days after discussion ended and a solution was marked. New replies are no longer allowed. You can open a new topic by clicking the link icon below the original post or solution and selecting “+ New Topic”.