JAVASCRIPT   77

image.js

Guest on 30th July 2021 02:49:55 PM

  1. import { addHeader } from './functions'
  2. import Print from './print'
  3.  
  4. export default {
  5.   print: (params, printFrame) => {
  6.     // Create the image element
  7.     let img = document.createElement('img')
  8.  
  9.     // Set image src with image file url
  10.     img.src = params.printable
  11.  
  12.     // Load image
  13.     img.onload = () => {
  14.       img.setAttribute('style', 'width:100%;')
  15.       img.setAttribute('id', 'printableImage')
  16.  
  17.       // Create wrapper
  18.       let printableElement = document.createElement('div')
  19.       printableElement.setAttribute('style', 'width:100%')
  20.       printableElement.appendChild(img)
  21.  
  22.       // Check if we are adding a header for the image
  23.       if (params.header) {
  24.         addHeader(printableElement, params.header, params.headerStyle)
  25.       }
  26.  
  27.       // Store html data
  28.       params.htmlData = printableElement.outerHTML
  29.  
  30.       // Print image
  31.       Print.send(params, printFrame)
  32.     }
  33.   }
  34. }

Raw Paste


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