在 Laravel 8 应用程序中,我使用 browsershot 制作 pdf 文件,它对我来说大部分工作正常,除了\n如果我的数据包含多个页面,我有 2 个问题:
\n我没有看到我用页脚定义的页眉(代码如下):https://i.stack.imgur.com/nujuf.jpg
\n我看到任何页面的最后一行被切断:https ://i.stack.imgur.com/63o1k.jpg
\n我通过传递到控制 html 内容和生成的文件名的代码来完成此操作:
\n $filename_to_save = $option_output_filename . \'.\' . $option_output_file_format;\n $save_to_file = \'generate_profile_card_\' . Session::getId() . \'_\' . $filename_to_save;\n\n $today_date = getCFFormattedDate(Carbon::now(config(\'app.timezone\')));\n $site_name = config(\'app.name\', \'\');\n\n $footerHtml = \'<div class="card-text d1" style="background-color: #ffffff !important; width: 100%; margin : 0 !important;">\n <table style="width: 100%; font-family: \\\'system-ui\\\'; font-size: 12px !important; padding : 20px 0 0 0 !important; margin: 0 …Run Code Online (Sandbox Code Playgroud) 我正在尝试为一个用 Laravel 编写的项目配置 Spatie/Browsershot,但在完成所有步骤后,我仍然收到一个错误:
“node”不被识别为内部或外部命令、可操作程序或批处理文件
A 已经安装了最新版本的 Node 和 npm,它们都存在于 PATH 中并且也可以在 cmd 上运行。
就像 GitHub 上的官方文档中写的那样,我运行了:
在我写的代码中:
use Spatie\Browsershot\Browsershot;
//Method to generate some random id
$unique_id = uniqid('img_');
//The path to the node and npm folders
$path_node = realpath('C:\\"Program Files"\\nodejs');
$path_npm = realpath('C:\\Users\\Hristo\\AppData\\Roaming\\npm');
//The $content is actually a stored HTML code
Browsershot::html("$content")->setScreenshotType('jpeg', 100)
->setNodeBinary($path_node)
->setNpmBinary($path_npm)
->save("$unique_id.jpeg");
Run Code Online (Sandbox Code Playgroud)
Program Files带有双引号,否则 Laravel 会因为两个单词之间的空格而抛出错误。
我不确定路径,它们写得正确吗?(windows中反斜杠的问题)