问题描述
我像鼹鼠一样用谷歌搜索,但找不到正确的方法.
I googled like a mole, but can´t find the right way to go.
我正在使用 WKHTMLTOPDF Wrapper Snappy 创建 PDF.
I´m creating a PDF with the WKHTMLTOPDF Wrapper Snappy.
如何将使用 generateFromHtml 方法生成的 pdf 直接发送到浏览器?这就是我想要做的:
How can I send the pdf generated with the method generateFromHtml straight to the Browser?Thats what I´m trying to do:
header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"');
echo $snappy->generateFromHtml($contents);
推荐答案
您想使用 getOutput/getOutputFromHtml
方法将 PDF 作为字符串返回,generate/generateFromHtml
将 PDF 保存到文件中并且不返回任何内容.
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);
GitHub 上的 Snappy GeneratorInterface 和文档
将 URL
$input
的 PDF 保存到文件$output
generate($input, $output, array $options = array(), $overwrite =假)
Save PDF of URL
$input
to file$output
generate($input, $output, array $options = array(), $overwrite = false)
将 HTML $html
的 PDF 保存到文件 $output
generateFromHtml($html, $output, array $options = array(), $overwrite = false)
Save PDF of HTML $html
to file $output
generateFromHtml($html, $output, array $options = array(), $overwrite = false)
以字符串形式返回 URL $input
的 PDF
getOutput($input, array $options = array())
以字符串形式返回 HTML $html
的 PDF
getOutputFromHtml($html, array $options = array())
这篇关于snappy wkhtmltopdf 包装器将生成的 html 文件发送到浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!