How can I create own pdf export button?

In a grid I have the standard pdf export button from the toolbar but I didn’t find a solution to run further php code if the pdf button is clicked. (would this be possible?)

So I would like to create a custom button that has the same function as the toolbar pdf button and I can execute some more php code when this button is clicked.

Any ideas what exactly happens when you click the toolbar pdf button and how to implement that in an own button?

I figured out that I can simulate the pdf export button with this code in an own javascript button

nm_gp_move('pdf', '0', 'cor');

This works and gives me the same as the pdf button from the toolbar. The background is that I need to add php code (file operations) if the button is clicked.
So I tried to create a php button with this and thought it would execute the javascript code

?>
<script type=“text/javascript”>
nm_gp_move(‘pdf’, ‘0’, ‘cor’);
</script>
<?php

But this takes me only to an empty page with an 'OK" button.

Can anybody tell me what I’m doing wrong? Why isn’t it the same as if I use a javascript button?