在pdf中进行Angular JS解析

时间:2014-02-26 16:46:30

标签: javascript html angularjs pdf

请参阅以下简单的html with angular js code

<!doctype html>
<html ng-app>
  <head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.13/angular.min.js"></script>
  </head>
  <body>
    <div ng-controller="MyCtrl">
  Hello, {{name}}!
</div>
<script type="text/javascript">

var myApp = angular.module('myApp',[]);

//myApp.directive('myDirective', function() {});
//myApp.factory('myService', function() {});

function MyCtrl($scope) {
    $scope.name = 'Superhero';
}
</script>

  </body>
</html>

当我在浏览器中打开这个html时,它会正常工作。但我想将此html内容导出为pdf。

读取html的所有contenats并在pdf文件中编写内容但是角度js代码未在pdf中解析。

//reading the html content

string contents = File.ReadAllText(path);

//writing the html content to pdf

File.WriteAllText(path, contents);

但pdf中的输出如

Hello, {{name}}!

这意味着它没有在pdf中解析。如何解决这个问题。

注意:我不想使用一些外部插件来生成角度js代码的pdf。我需要在C#中进行简单的读写操作。

1 个答案:

答案 0 :(得分:1)

您之所以这样做是因为您只是从服务器读取HTML响应,而不是在调用页面上 Javascript 后实际生成的内容。

您需要启动一个实际浏览器的实例,该实例解释页面上的Javascript,然后从那里读取输出。您可以尝试使用的一个API是Selenium,我在Java和PHP应用程序中都使用过它,但它们也有.NET client driver