繁体   English   中英

使用 Print.js 打印 PDF 文件

[英]Print PDF File using Print.js

我很难显示通过 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)

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

有什么建议吗?

查看https://printjs.crabbly.com/#configuration我发现还有一些配置选项可能会为您提供线索。 我建议尝试这个(我添加了 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)

那么我的故障排除问题将是:

  • 如果您查看该页面的 url,将 /53544.pdf 附加到正确的位置?
  • 如果您查看开发人员工具的网络选项卡,您是否看到正在请求 pdf,它是否成功?

暂无
暂无

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

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