h2p
h2p copied to clipboard
Error Executing a Test PDF
Here is my script in the PHP file:
require_once("include/h2p/autoloader.php"); use H2P\Converter\PhantomJS; use H2P\TempFile;
$converter = new PhantomJS(); $input = new TempFile('test string to pdf', 'html'); // Make sure the 2nd parameter is 'html'
$converter->convert($input, '/pdf/testpage.pdf');
Here is the error:
Fatal error: Uncaught exception 'H2P\Exception' with message 'Error while executing PhantomJS: ""' in /h2p/src/H2P/Converter/PhantomJS.php:283 Stack trace: #0 /h2p/src/H2P/Converter/ConverterAbstract.php(136): H2P\Converter\PhantomJS->transform(Object(H2P\Request), '/...') #1 /h2ptest.php(19): H2P\Converter\ConverterAbstract->convert(Object(H2P\TempFile), '/...') #2 {main} thrown in /h2p/src/H2P/Converter/PhantomJS.php on line 283
Did you downloaded the phantomjs binaries and put it on the right folder?
Yes, I downloaded, extracted, and placed in the h2p/bin/linus-x86_64 folder.
At first, i was getting an error about the binaries not being found, but I changed its permission to 777 and it gave the new error.
It doesn't look like PHP executed phantom at all. Can you try this code below and tell me its output?
echo shell_exec('bin/linux-x86_64/phantomjs -v');
All the page says is:
1.9.7
That's expected. Can you do a chmod +x
in the bin/converter.js
file and try again?
Edit: No, wait, this won't work either.
No change, exact same error when running the original php script
The script is creating a pdf file in the folder, but the pdf is corrupt (0kb). It's also blank when I open in a text editor.
In case that helps at all.
Does not work with simple example, phantomjs 1.9.7:
PHP Fatal error: Uncaught exception 'H2P\Exception' with message 'Error while executing PhantomJS: "SyntaxError: Unable to parse JSON string"' in \vendor\kriansa\h2p\src\H2P\Converter\PhantomJS.php:283
Stack trace:
#0 C:\Users\Tomas\PhpstormProjects\zibintas_naudoti\vendor\kriansa\h2p\src\H2P\Converter\ConverterAbstract.php(136): H2P\Converter\PhantomJS->transform(Object(H2P\Request), 'page.pdf')
#1 C:\Users\Tomas\PhpstormProjects\zibintas_naudoti\vendor\convert.php(14): H2P\Converter\ConverterAbstract->convert('http://www.goog...', 'page.pdf')
#2 {main}
thrown in \vendor\kriansa\h2p\src\H2P\Converter\PhantomJS.php on line 283
Fatal error: Uncaught exception 'H2P\Exception' with message 'Error while executing PhantomJS: "SyntaxError: Unable to parse JSON string"' in \vendor\kriansa\h2p\src\H2P\Converter\PhantomJS.php on line 283
H2P\Exception: Error while executing PhantomJS: "SyntaxError: Unable to parse JSON string" in \vendor\kriansa\h2p\src\H2P\Converter\PhantomJS.php on line 283
That could be because the page that phantomjs is rendering carries on that error. I'm planning to create a PR with an updated version of the converter. However if you want to make a try, I have a fork of it in my repos.
@topazas Have you tried another html file? Maybe it's because you had a JS error as described by @ilpaijin.
Hello! I have the same error of @topazas , I tried use the simple example.
I'm having the same problem as @topazas and @gustavowiller. I've tried the simple example and I'm getting nothing back from the processor. I'm running this on a mac (yosemite). I have the binary in place, I tried running chmod +x on the file and I'm just getting nothing back from the shell execution. Same line number - the $result
is blank.
EDIT: I get this when doing a convert on google.com and also when doing a simple HTML conversion $input = new \H2P\TempFile("<b>test</b>", 'html');
EDIT AGAIN: when I try to run the shell commands directly in terminal I get "Killed: 9". The zero-byte file shows up.
E aí @kriansa tranquilo?
Kra, estou com um probleminha, baixei seus 2 repositórios - openboleto e H2P - fazendo testes no Windows (8.1) tive a seguinte mensagem de erro - Error while executing PhantomJS: "SyntaxError: JSON Parse error: Expected '}'"
Baixei o phantomjs.exe e coloquei no diretório win32 conforme orientações da documentação e nada.
Estou usando CakePHP para minha aplicação.
Uma coisa estranha que reparei, é que ele diz não ter permissão para escrever o arquivo no diretório temporário "The destination file is not writable!" no ConverterAbstract.php na linha 132
Já tentei todos os exemplos e nada. Se tiver um tempo para uma ajuda... obrigado man.
Hmmm same error here on OSX Yosemite. Anybody got a working solution?
Seems like the temp file can't be created. Will try tonight on linux machine....
edit hmmm seems like there aren't any binary packages for linux yet :(
Well, i got it running using on a linux server. Unfortunately you have to compile your own binary for linux if you want to use PhantomJS versions > 2.0
1.9.8 (x64) can be downloaded here: https://bitbucket.org/ariya/phantomjs/downloads/$PHANTOM_JS.tar.bz2
More info: https://gist.github.com/julionc/7476620