Sc_pdf_output breaks pdf report

I’m trying to set, at runtime, the output file name of a pdf report app

I’ve tried both sc_pdf_output and the native $pdf->Output and also using them in different pdf events (Body, Header, etc.).

In the events where sc_pdf_output or $pdf->Output are able to change the file name, the result is that the printed output in the pdf document stops after just the header on the first page.
Nothing else is printed.

When I remove the sc_pdf_output or $pdf->Output line the PDF is generated correctly, all lines and pages, but with the tmp file name that I’m trying to avoid.

Can anyone help me make it work?

MORE INFO:
In the app, PDF Report > Settings > PDF Destination is set as “Browser”.
So the PDF is open in the browser.
The file name set in SC is used to populate the save dialog, when the user click on the floppy icon to save the pdf file.