Javascript 使用角度数据从php创建word/pdf文件

Javascript 使用角度数据从php创建word/pdf文件,javascript,php,angularjs,Javascript,Php,Angularjs,我想在word文档中输出一个表单。。通过一些研究,我得到的最佳解决方案是使用php header(),即 我很容易用这个方法创建了简单的word文件, 但在我的项目中,我从angularjs获取数据。。这是我在Angular Controller中的代码 $scope.createdoc = function () { $scope.textContent = "hello"; var request = $http({ method: "post",

我想在word文档中输出一个
表单
。。通过一些研究,我得到的最佳解决方案是使用php header(),即

我很容易用这个方法创建了简单的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>";

我做错什么了吗?有什么解决方案吗?

我不认为你能如此轻松地生成一个Office Word文档,只需几个标题,别的什么都没有

记住使用正确的书写器

$objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$objWriter->save('helloWorld.docx');

祝你好运

我最终并行完成了AngularJS和PHP。。。 我的代码是这样的

Document created successfully <html><meta http-equiv="Content-Type" content="text/html; charset=Windows-1252"><body><p>This is Document body</p></body></html>
<?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>";
}
?>

但是我使用了我的项目只有php版本的标题。。。它只是不工作在这里,我试图输出角度范围值。。。只有这两行是额外的
$json=file\u get\u contents(“php://input"); $array=json_decode($json,true)
<?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>";
}
?>