简体   繁体   English

使用 Print.js 打印 PDF 文件

[英]Print PDF File using Print.js

I'm having difficulties to show print modal passing a pdf file.我很难显示通过 pdf 文件的打印模式。

    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.它只是与pdf 文件有关,我用logo.png之类的图像进行了测试,它工作正常。 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!我将该参数插入回调以试图弄清楚发生了什么,并且触发了OnPrintDialogClose() ,但模式框没有显示! The screen blink and this message is showed 'The print dialog was closed' .屏幕闪烁并显示此消息'The print dialog was closed'

Any suggestion?有什么建议吗?

Looking at https://printjs.crabbly.com/#configuration I see there are some more configuration options that might give you clues.查看https://printjs.crabbly.com/#configuration我发现还有一些配置选项可能会为您提供线索。 I would recommend trying this (I added onError and modalMessage):我建议尝试这个(我添加了 onError 和 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?如果您查看该页面的 url,将 /53544.pdf 附加到正确的位置?
  • If you look in the network tab of your developer tools do you see the pdf being requested and is it successful?如果您查看开发人员工具的网络选项卡,您是否看到正在请求 pdf,它是否成功?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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