My goal is to open a PDF in a new browser tab and to fire JavaScript. I have two problems:
The PDF does not get displayed in Firefox. I see the PDF viewer elements, but no page is displayed and I get the message that the PDF cannot get rendered correctly.
In Chrome, the PDF gets displayed. However, the JavaScript does not fire.
Here comes my code:
$file = file_get_contents('http://bililite.com/blog/blogfiles/pdf/preschool%20physical-fields.pdf');
$js = <<<EOT
/Names << /JavaScript <</Names [ (EmbeddedJS) <<
alert('test');
) >> ] >> >>
EOT;
$file = preg_replace(
'#/Type\s*/Catalog#',
'$0'.$js,
$file
);
header("Content-type: application/pdf");
echo $file;