我正在使用PHP创建一个程序,接受来自表格的数据,然后创建20个不同的DOC文件,可以在单击时下载。我已经完成了这一切,如果您单击20个文件的URL,它会弹出窗口将这些文件保存为Word文件。现在我正在尝试实现从程序本身一键打印所有这些文件,而不需要保存它们。这些数据来自于数据库,因此是动态的。是否可能通过一键操作打印这些Word文件?另外,有些文档可能有多个副本。
<?php
header('Content-Type: application/vnd.ms-word');
header('Content-Disposition: attachment;filename="myfile.docx"');
header('Cache-Control: max-age=0');
// Code that generates DOC
// output the file to the browser
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWriter->save('php://output');
exit;
?>
在你的 PHP 或任何 HTML 代码的顶部
<?php
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("content-disposition: attachment;filename=Report.doc");
?>