【问题标题】:Angular JS parsing in pdfpdf中的Angular JS解析
【发布时间】:2014-03-29 15:50:34
【问题描述】:

请参考下面带有角度js代码的简单html

<!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 的所有内容并将内容写入 pdf 文件,但 angular 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 中解析。如何解决这个问题。

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

【问题讨论】:

    标签: javascript html angularjs pdf


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-06
      • 2015-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      • 1970-01-01
      • 2017-04-18
      相关资源
      最近更新 更多