以下是一个简单的PHP打印页面的示例代码:
<?php
// 设置页面编码为UTF-8
header('Content-Type: text/html; charset=utf-8');
// 获取要打印的页面内容
$pageContent = file_get_contents('http://www.example.com/print-page.php');
// 创建一个隐藏的iframe,并将页面内容写入其中
echo '<iframe id="print-frame" style="display:none;"></iframe>';
echo '<script>';
echo 'var printFrame = document.getElementById("print-frame");';
echo 'printFrame.contentDocument.write(' . json_encode($pageContent) . ');';
echo 'printFrame.contentDocument.close();';
echo 'printFrame.contentWindow.print();'; // 打印页面
echo '</script>';
?>
请注意,此示例假设您要打印的页面位于http://www.example.com/print-page.php
。您需要将其替换为实际要打印的页面的URL。此外,您可能需要根据实际需求进行一些调整和修改。
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站