You want to use the getOutput/getOutputFromHtml
methods to return the PDF as a string, generate/generateFromHtml
will save the PDF to a file and not return anything.
header('Content-Type: application/pdf');
// Remove the next line to let the browser display the PDF
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->getOutputFromHtml($contents);
Snappy GeneratorInterface and documentation on GitHub
Save PDF of URL
$input
to file$output
generate($input, $output, array $options = array(), $overwrite = false)Save PDF of HTML
$html
to file$output
generateFromHtml($html, $output, array $options = array(), $overwrite = false)Return PDF of URL
$input
as string
getOutput($input, array $options = array())Return PDF of HTML
$html
as string
getOutputFromHtml($html, array $options = array())