The rasterize methods accepts a callback as the 4th parameter.
$response = new Response(
$this->get(Rasterizer::class)->rasterize(
$this->renderView('Bundle:Folder:template.pdf.twig'),
[],
[],
function (Process $process) {
// HERE
}
),
200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="my.pdf"'
]
);