Javascript Angular JS 生成 PDF - 任何创建者 - 制造商模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28072351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:11:28  来源:igfitidea点击:

Angular JS generating PDF - any creator - maker modules?

javascriptangularjspdfmeanjs

提问by Stweet

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

正如标题所说,是否有任何用于 Angular 的 PDF 创建器/生成器?

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.

我看过https://github.com/MrRio/jsPDF,但找不到任何适用于 Angular 的内容。我想将 html 页面制作为 pdf 文件以供下载。

采纳答案by Enzey

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 .

您可以将您提到的 JavaScript 项目包装到您在整个应用程序中调用的服务中。这实际上是一种相当标准的做法,如果您需要更改底层实现,它还可以隔离您的代码。

回答by stackSean

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

看起来@Mike 已经关闭了。一些快速更改生成了一个看起来不错的文件,并弹出了一个打印弹出窗口。

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

1 - 为您要打印的区域指定“printArea”的 ID

2 - Add the $windowservice

2 - 添加$window服务

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

回答by Milox

There's this Angular directive wrapping up jsPDFfunctionality:

有这个 Angular 指令包装了jsPDF功能:

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

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

回答by Mike

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

您可以使用 window.print() 来打印当前的 HTML 文档。使用媒体查询来调整样式文档。您可以快速构建文档并随时调用打印

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

  };