简体   繁体   English

如何发送 pdf 以在 Angular 中单击按钮进行打印?

[英]How to send a pdf to printing on button click in Angular?

I need to implement the print operation for my Angular 6 application.我需要为我的 Angular 6 应用程序实现打印操作。 A pdf will be fetched from service and then on button click, I need to send it to printing.将从服务中获取 pdf,然后单击按钮,我需要将其发送到打印。 There will be no preview of the PDF.将不会有 PDF 预览。 So, I can't use the print option of PDF.所以,我不能使用 PDF 的打印选项。 Can anyone help me in this regard?任何人都可以在这方面帮助我吗?

I've tried print.js and jsPdf.我试过print.js 和jsPdf。 jsPdf requires to download the pdf and then open it to print. jsPdf需要下载pdf然后打开打印。 But I need to do it by a button click.但我需要通过单击按钮来完成。 Print.js throws this error- (I'm using Chrome) Print.js 引发此错误-(我正在使用 Chrome)

ERROR DOMException: Blocked a frame with origin "http://localhost:4200" from accessing a cross-origin frame.
at performPrint (http://localhost:4200/modules-deposit-dashboard-deposit-dashboard-module.js:1025:33)
at finishPrint (http://localhost:4200/modules-deposit-dashboard-deposit-dashboard-module.js:1061:5)
at HTMLIFrameElement.printFrame.onload [as __zone_symbol__ON_PROPERTYload] (http://localhost:4200/modules-deposit-dashboard-deposit-dashboard-module.js:980:11)
at HTMLIFrameElement.wrapFn (http://localhost:4200/polyfills.js:12361:39)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:11594:31)
at Object.onInvokeTask (http://localhost:4200/vendor.js:42637:33)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (http://localhost:4200/polyfills.js:11593:36)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (http://localhost:4200/polyfills.js:11361:47)
at ZoneTask.push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask [as invoke] (http://localhost:4200/polyfills.js:11669:34)
at invokeTask (http://localhost:4200/polyfills.js:12713:14)

对于打印,您需要将文件加载到框架内的单独窗口中,然后才能将其发送到打印机进行打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM