简体   繁体   中英

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

I need to implement the print operation for my Angular 6 application. A pdf will be fetched from service and then on button click, I need to send it to printing. There will be no preview of the PDF. So, I can't use the print option of PDF. Can anyone help me in this regard?

I've tried print.js and jsPdf. jsPdf requires to download the pdf and then open it to print. But I need to do it by a button click. Print.js throws this error- (I'm using 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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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