Print PDF File using Print.js

4.1k views Asked by At

I'm having difficulties to show print modal passing a pdf file.

    setTimeout(() => {            
        printJS({
        printable: '53544.pdf',
        type: 'pdf',
        showModal: true,    
        fallbackPrintable: () => console.log("FallbackPrintable"),      
        onPrintDialogClose: () => console.log('The print dialog was closed'),
        onIncompatibleBrowser: () => console.log('Pdf was opened in a new tab due to an incompatible browser')
        })
        console.log("TimeOut Executado");
        }
        ,3000)

It is happing just with pdf files, I tested with image like logo.png and it worked. I insert that params to callback to trying to figured out what is happing, and OnPrintDialogClose() is trigged, but the modal box did not show! The screen blink and this message is showed 'The print dialog was closed'.

Any suggestion?

1

There are 1 answers

3
Sydney Y On

Looking at https://printjs.crabbly.com/#configuration I see there are some more configuration options that might give you clues. I would recommend trying this (I added onError and modalMessage):

setTimeout(() => {            
  printJS({
    printable: '53544.pdf',
    type: 'pdf',
    showModal: true, 
    modalMessage: "Document Loading...",
    onError: (err) => console.log(err),
    fallbackPrintable: () => console.log("FallbackPrintable"),      
    onPrintDialogClose: () => console.log('The print dialog was closed')
  });
  console.log("TimeOut Executado");
  }, 3000)

Then my troubleshooting questions would be:

  • If you look at the url of that page, appending /53544.pdf the right location?
  • If you look in the network tab of your developer tools do you see the pdf being requested and is it successful?