JAVASCRIPT   75

pdf.js

Guest on 30th July 2021 02:53:53 PM

  1. import Browser from './browser'
  2. import Print from './print'
  3.  
  4. export default {
  5.   print: (params, printFrame) => {
  6.     // If showing feedback to user, pre load pdf files (hacky)
  7.     if (params.showModal || params.onLoadingStart || Browser.isIE()) {
  8.       let req = new window.XMLHttpRequest()
  9.       req.addEventListener('load', send(params, printFrame))
  10.       req.open('GET', window.location.origin + params.printable, true)
  11.       req.send()
  12.     } else {
  13.       send(params, printFrame)
  14.     }
  15.   }
  16. }
  17.  
  18. function send (params, printFrame) {
  19.   // Set iframe src with pdf document url
  20.   printFrame.setAttribute('src', params.printable)
  21.  
  22.   Print.send(params, printFrame)
  23. }

Raw Paste


Login or Register to edit or fork this paste. It's free.