Easily print Pdf link in Javascript/Angular (Solved)

We are going to use print.js library: https://printjs.crabbly.com/

1. For Html/Javascript Project

a) in HTML file define these links

<link rel="stylesheet" type="text/css" href="https://printjs-4de6.kxcdn.com/print.min.css">

b) Now global method printjs is available

printJS({printable:'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf', type:'pdf', showModal:true})

2. If you are using Angular 2+

Follow given steps to implement pdf preview in Agular 2+

  1. npm install print-js --save
  2. import printJS from 'print-js'; in component.ts code
  3. tsconfig.json: "allowSyntheticDefaultImports": true, option incompilerOptions

Now you can use printJs method inside component.ts code -

ngOnInit() {

This will open a print preview in the browser :)

If you like this Article give a clap and write in comment section.

--

--

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK...Love to write cool stuff

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shivam Gupta

Full Stack Engineer (Web/App) working on different JS Technologies & frameworks— Angular, Node, Typescript, Ionic, Firebase, AWS, ElK...Love to write cool stuff