Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PDF JavaScript不再在Edge中运行_Javascript_Pdf_Fpdf - Fatal编程技术网

PDF JavaScript不再在Edge中运行

PDF JavaScript不再在Edge中运行,javascript,pdf,fpdf,Javascript,Pdf,Fpdf,在通过浏览器查看的FPDF/PHP生成的PDF中运行JavaScript时,我遇到了一些问题。脚本应该显示打印对话框或消息框。此功能已运行多年,但最近对Edge/Windows的更新似乎破坏了此功能。经过调查,基于浏览器/查看器的行为似乎有所不同 关于完全更新的Windows 10的调查结果: Edge:PDF在Edge自己的查看器中打开,打印对话框不会出现 Firefox:PDF将在Firefox自己的查看器中打开,并显示打印对话框 资源管理器:PDF在默认PDF查看器中打开,并显示“打印”

在通过浏览器查看的FPDF/PHP生成的PDF中运行JavaScript时,我遇到了一些问题。脚本应该显示打印对话框或消息框。此功能已运行多年,但最近对Edge/Windows的更新似乎破坏了此功能。经过调查,基于浏览器/查看器的行为似乎有所不同

关于完全更新的Windows 10的调查结果:

  • Edge:PDF在Edge自己的查看器中打开,打印对话框不会出现
  • Firefox:PDF将在Firefox自己的查看器中打开,并显示打印对话框
  • 资源管理器:PDF在默认PDF查看器中打开,并显示“打印”对话框
与呼叫消息框的情况相同

我像示例中指定的那样扩展FPDF


难道不能指望PDF JavaScript功能在不同的浏览器/查看器中被允许吗

这是不可能的。据我所知,您尝试运行的JavaScript仅在Adobe Acrobat和Reader以及其他几个桌面PDF查看器和一个移动PDF查看器中有效。该代码在Edge中不起作用,因为Edge有自己的内置PDF查看器,Explorer将使用Adobe Reader或Acrobat、Foxit、Nuance、Nitro或其他操作系统级别的阅读器来显示PDF,这就是为什么会出现该对话框


简而言之,您不能指望有合适的查看器/浏览器/操作系统组合来运行PDF中的任何JavaScript

你查过浏览器控制台日志了吗?@你说的是F12控制台选项卡吗?在那里,我只得到一个信息(出现导航)和两个警告(预期使用DOCTYPE并禁用了反向和正向缓存)。我不确定这是怎么可能的。
<?

require('fpdf.php');

class PDF_JavaScript extends FPDF {

    // My code start
    function OpenPrintDialog()
    {
        $this->IncludeJS("print(true);");
    }

    function ShowMessageMessage($text)
    {
        $this->IncludeJS("app.alert('$text', 3);");
    }
    // My code end

    protected $javascript;
    protected $n_js;

    function IncludeJS($script, $isUTF8=false) {
        if(!$isUTF8)
            $script=utf8_encode($script);
        $this->javascript=$script;
    }

    function _putjavascript() {
        $this->_newobj();
        $this->n_js=$this->n;
        $this->_put('<<');
        $this->_put('/Names [(EmbeddedJS) '.($this->n+1).' 0 R]');
        $this->_put('>>');
        $this->_put('endobj');
        $this->_newobj();
        $this->_put('<<');
        $this->_put('/S /JavaScript');
        $this->_put('/JS '.$this->_textstring($this->javascript));
        $this->_put('>>');
        $this->_put('endobj');
    }

    function _putresources() {
        parent::_putresources();
        if (!empty($this->javascript)) {
            $this->_putjavascript();
        }
    }

    function _putcatalog() {
        parent::_putcatalog();
        if (!empty($this->javascript)) {
            $this->_put('/Names <</JavaScript '.($this->n_js).' 0 R>>');
        }
    }
}

$pdf = new PDF_JavaScript();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 20);
$pdf->Text(90, 50, 'Print me!');

$pdf->OpenPrintDialog();
// or
//$pdf->ShowMessageMessage('Message box me!');

$pdf->Output();

?>