最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular JS generating PDF - any creator - maker modules? - Stack Overflow

programmeradmin2浏览0评论

As title says, is there any PDF creator / generator for Angular?

I have seen , but can't find any for Angular. I want to make an html page to a pdf file for download.

As title says, is there any PDF creator / generator for Angular?

I have seen https://github.com/MrRio/jsPDF, but can't find any for Angular. I want to make an html page to a pdf file for download.

Share Improve this question edited Jan 21, 2015 at 17:26 theadam 4,0515 gold badges27 silver badges41 bronze badges asked Jan 21, 2015 at 16:39 StweetStweet 7033 gold badges12 silver badges27 bronze badges 2
  • 1 I've the same question. I've tried jsPDF but it has some problems, like alignment issues. Sometimes it seems as if some layers overlap its parent's border and some times image does not appear. So, i was wondering if there is an AngularJS library or anyother alternative library/module for creating PDF out of the web page. – Temp O'rary Commented Jun 18, 2015 at 4:48
  • 1 Use this solution from a 99% similar question here: stackoverflow.com/questions/34049956/… – NaN Commented Jun 24, 2016 at 13:52
Add a comment  | 

4 Answers 4

Reset to default 6

You can wrap the JavaScript project you mentioned into a service that you call throughout your app. This is actually a rather standard practice and it also isolates your code if you ever need to change the underlying implementation .

Looks like @Mike had it close there. A few quick changes generated a decent looking file and brought up a print pop-up.

1 - Give the area that you want to print an ID of 'printArea'

2 - Add the $window service

$scope.printIt = function(){
   var table = document.getElementById('printArea').innerHTML;
   var myWindow = $window.open('', '', 'width=800, height=600');
   myWindow.document.write(table);
   myWindow.print();
};

You can use window.print() which prints current HTML document. Use media queries to adjust styles document. You can build your document in fly and call print anytime you want

@media print { 
 /* All your print styles go here */
 #header, #footer, #nav { display: none !important; } 
}

Some code from one of my project, print's only content from table:

 $scope.print = function () {
    console.log('modal print');

    var table = document.querySelector('.CSSTableGenerator').innerHTML;
    var myWindow = window.open('', '', 'width=800, height=600');
    myWindow.document.write(table);
    myWindow.print();

  };

There's this Angular directive wrapping up jsPDF functionality:

https://github.com/sayanee/angularjs-pdf

发布评论

评论列表(0)

  1. 暂无评论