【问题标题】:How to print a PHP file using PrintJS?如何使用 PrintJS 打印 PHP 文件?
【发布时间】:2022-11-24 17:54:53
【问题描述】:

我遇到了一个问题,我想在 PHP 中使用 PrintJS 库。我创建了一个 PHP 文件,它是 invoice.php,我想使用该库将其打印为 PDF。我还创建了一个 JavaScript 函数,我在其中调用了 printJS 函数。我怎样才能使用 JavaScript 将 PHP 文件查看为 PDF

这是我的 invoice.php,我想在其中使用添加了 printJS 函数的 JavaScript 函数打印出来:

这是我添加 PrintJS 函数来打印 PHP 文件的函数

function print_invoice() {
    printJS({
        printable: base_url + "shipment/invoice",
        type: 'pdf',
        targetStyles: ['*']
    })
}

【问题讨论】:

    标签: javascript php printjs


    【解决方案1】:
        <script>
      function getFileAndPrint() {
        // Generate pdf and get its filename  
        // Assuming your are writing this in a .php file  
        let printFile = '<?php echo $variable; ?>'  
    
        // Freedom to do anything else you may want to
        // ...
    
        // Pass pdf to printJS
        printJS(printFile)
      }
    </script>
    

    【讨论】:

      猜你喜欢
      • 2019-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-07
      • 2012-03-31
      相关资源
      最近更新 更多