【问题标题】:Load HTML content from URL AngularJS从 URL AngularJS 加载 HTML 内容
【发布时间】:2018-01-21 17:36:03
【问题描述】:

我正在尝试从使用 angularjs 生成的 HTML 生成 PDF,但是当我使用 angular URL 来请求(通过requestify)而不是页面内容时,我得到了index.html 页面的内容...有谁知道如何在ng-view 上生成 HTML 内容

$routeProvider .when('/mediakit/:account', { templateUrl: 'app/mediakit/mediakit.html', controller: 'MediaKitCtrl' });

我想要来自使用mediakit.html 作为模板的http://localhost:9000/mediakit/accountid 的内容,而不是index.html 的内容(通过ng-view 加载内容)

我用来生成 PDF 的代码

    let pdf = require('html-pdf');
      let requestify = require('requestify');
      let outputPath = './server/public/';
      //req.body.mediaKitURL --> is the URL that I load the content when I open in the browser
      requestify.get(req.body.mediaKitURL).then(function (response) {
        // Get the raw HTML response body
        let html = response.body; --> //the content here is the content from index.html, 
      //I would like to get the content from the my angular route that uses mediakit.html (same when I open the URL in the browser)
        let config = {format: 'letter'}; 

    // Create the PDF
        pdf.create(html, config).toFile(outputPath + '/media_kit_'+req.params.account+'.pdf', function (err, result) {
          if (err) return console.log(err);
          console.log(result); // { filename: '/pathtooutput/generated.pdf' }
          res.status(200).json();
        });
      });

我希望这很清楚......

【问题讨论】:

    标签: javascript html angularjs pdf-generation


    【解决方案1】:

    我认为您正在搜索 pdf 查看器以显示生成的 pdf 文件内容。

    为此,请参考下面的 angularjs 指令,

    https://github.com/legalthings/angular-pdfjs-viewer

    【讨论】:

    • 这不是我要找的。​​span>
    猜你喜欢
    • 1970-01-01
    • 2017-05-01
    • 2019-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多