Skip to content
This repository has been archived by the owner on Nov 24, 2020. It is now read-only.

Error Executing a Test PDF #12

Open
bdowd625 opened this issue Aug 20, 2014 · 15 comments
Open

Error Executing a Test PDF #12

bdowd625 opened this issue Aug 20, 2014 · 15 comments

Comments

@bdowd625
Copy link

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

@kriansa
Copy link
Owner

kriansa commented Aug 20, 2014

Did you downloaded the phantomjs binaries and put it on the right folder?

@bdowd625
Copy link
Author

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.

@kriansa
Copy link
Owner

kriansa commented Aug 20, 2014

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');

@bdowd625
Copy link
Author

All the page says is:

1.9.7

@kriansa
Copy link
Owner

kriansa commented Aug 20, 2014

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.

@bdowd625
Copy link
Author

No change, exact same error when running the original php script

@bdowd625
Copy link
Author

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.

@tmsnvd
Copy link

tmsnvd commented Sep 23, 2014

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

@ilpaijin
Copy link

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.

@kriansa
Copy link
Owner

kriansa commented Oct 31, 2014

@topazas Have you tried another html file? Maybe it's because you had a JS error as described by @ilpaijin.

@gustavowiller
Copy link

Hello! I have the same error of @topazas , I tried use the simple example.

@sparkweb
Copy link

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.
shell_command

@gildonei
Copy link

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.

@Bechrissed
Copy link

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 :(

@Bechrissed
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants