I have installed the PDFResources snippet / plugin - It functions well from the manager generating the pdf page on view but how do I fire the snippet from a click or link on the front end.
I have a page of user entered form data and want the user to be able to download a copy as a PDF - how do I fire the snippet from there.
According to the documentation to generate the PDF on the fly, you have to “assign the template variable live_pdf to a template and check this template variable on a resource.”
Maybe you can use a Symlink for one of these resources, so you don’t have to duplicate the content.
Alternatively you could extend the plugin with some custom code:
Duplicate the plugin “PDFResource” and deactivated the original one.
Then add some code to the top of your new plugin.
//Check if PDF should be displayed
$resource_id_with_pdf = 12; //change the value to the id of your resource!
if($modx->event->name == 'OnWebPagePrerender') {
if ($modx->resource->get('id') == $resource_id_with_pdf){
if (!isset($_GET["pdf"]) || $_GET["pdf"] != "1") {
return; //don't execute the rest of the plugin
}
}
}
//original plugin code
...
Now when you call your page with a GET parameter ?pdf=1 it should return a PDF, otherwise it shows the normal page.