Angular JS generating PDF - any creator - maker modules?

房东的猫 提交于 2019-11-29 09:27:32

问题


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.


回答1:


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 .




回答2:


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();
};



回答3:


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();

  };



回答4:


There's this Angular directive wrapping up jsPDF functionality:

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



来源:https://stackoverflow.com/questions/28072351/angular-js-generating-pdf-any-creator-maker-modules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!