用angular数据从php创建word/pdf文件
Create word/pdf file from php with angular data
我想在word文档中输出form
..最好的解决方案,我得到了一些研究是使用php header(),即
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=output.doc");
我已经很容易地用这个方法创建了一个简单的word文件。但在我的项目中,我从angularjs获得数据…这是我在Angular Controller中的代码。
$scope.createdoc = function () {
$scope.textContent = "hello";
var request = $http({
method: "post",
url: "doc.php",
data: {
items: $scope.items,
length: $scope.items.length
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
request.success(function (data) {
$scope.textContent = "Document created successfully "+data;
});
}
这是我在doc.php
$json = file_get_contents("php://input");
$array = json_decode($json, true);
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=output.doc");
echo "<html>";
echo "<meta http-equiv='"Content-Type'" content='"text/html; charset=Windows-1252'">";
echo "<body>";
echo "<p>This is Document body</p>";
echo "</body>";
我以前在简单的php文件中这样做过,该文件提示下载doc
文件,内容为This is Document body
,但这次,它在我打印$作用域的html页面中显示所有这些echo'ed行。textContent i.e. {{textContent}}
,
Document created successfully <html><meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"><body><p>This is Document body</p></body></html>
我做错了什么吗?有解决方案吗?
我不认为你可以这么容易地生成一个Office Word文档,只有几个标题和其他的。
这个PHP库可以创建一个Word文件
下面是一个如何使用phoffice/PHPWord创建Office Word 2007文件的简单示例记住使用正确的写法$objWriter = 'PhpOffice'PhpWord'IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');
好运我最终并行做AngularJS和PHP…我的代码是这样的
<?php
if(isset($_POST["submit"])) {
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=output.doc");
echo "<html>";
echo "<meta http-equiv='"Content-Type'" content='"text/html; charset=Windows-1252'">";
echo "<body>";
echo "<p style = '"color: $_POST["color"]; font-size: $_POST["font"].px; font-family: $_POST["family"]'">{$_POST['text']}</p>";
echo "</body>";
echo "</html>";
}
?>
这不是分配值给$scope
变量,然后在PHP中使用它们,我使用ng-model
和name
字段在输入标签…
相关文章:
- 如何使用javascript或html下载PDF格式的填写表单
- 如何将PDF作为二进制文件传递到window.open()
- javascript.点击显示嵌入的pdf
- Javascript/Jquery Blob not showing Chrome PDF
- 在提交时打开thankyou.html+下载PDF
- 生成pdf或其他非html文件时的错误处理
- how to convert html <div> to pdf
- 使用TableExport.js将HTML表格导出为PDF、WORD、PNG
- 下载pdf/word按钮javascript /jquery
- 如何使用Javascript单击下载多个文档(word,ppt,pdf)
- Ajax响应对于word文档为空,对于txt和pdf则为空
- 客户端Microsoft Word到PDF的转换-如何在MVC3中
- 在c#中下载html文本区域标签的内容为word或pdf文件
- 在JavaScript中是否可以将字节数组/流转换为Word,Excel, PDF等文件?
- 用angular数据从php创建word/pdf文件
- 为PDF/Microsoft Word下载的站点添加事件跟踪
- 当点击angularjs中的链接时,如何打开word/Excel/PDF文件
- 类似于Word文档的pdf.js
- 关于MathJax的特定问题,然后(自动?)保存为word或pdf
- 是二进制文件(pdf, word, excel, ppt, mp3,..)下载可能使用XHR或fetch