0

I want to convert a pdf into html in PHP by running this command

pdftohtml -i -c test/invoice.pdf test/invoice.html

but it's not working using this PHP code

$data=exec('pdftohtml -i -c test/invoice.pdf test/invoice.html');
5
  • Does your apache/nginx user have write permission? Commented Jul 10, 2017 at 11:58
  • yes it have , should i have to give path or any thing else ? Commented Jul 10, 2017 at 11:59
  • 1
    Yes, add the full path to your files in your command Commented Jul 10, 2017 at 12:00
  • added no output Commented Jul 10, 2017 at 12:03
  • what ends up in invoice.pdf, does it contain the pdf as expected? Commented Jul 10, 2017 at 14:53

4 Answers 4

1

I have solved above question by giving permission to folder having issue due to folder is not writable its difficult for me to find because it's not showing any error on my Ubuntu machine, even its error mode and debugging is on.

Sign up to request clarification or add additional context in comments.

Comments

0

You may need to run the command as root.

I had this issue once and ended up writing a script that SSH'd into itself.

$this->root_execute('pdftohtml -i -c test/invoice.pdf test/invoice.html');

-

public function root_execute($command = '')
{
    set_include_path('/path/to/dir/ssh/');
    require_once('Net/SSH2.php');

    $ssh = new Net_SSH2(SSH_HOST);

    if (!$ssh->login(SSH_USER, SSH_PASS)) {
        exit('failed');
    }
    $res = $ssh->exec($command);
    $ssh = null;
    restore_include_path();
    return $res;
}

1 Comment

Did you get SSH2?
0

what kind of error you get after execute the command? try maybe other feature etc. shell_exec http://php.net/manual/ru/function.shell-exec.php

1 Comment

this should be a comment, not an answer
0

You may need to provide the full path for the pdftohtml. For example if you are on linux you can do

whereis pdftohtml

You may then see /usr/bin for example, therefore changing the line to read

/usr/bin/pdftohtml -i -c ./test/invoice.pdf ./test/invoice.html

This may resolve your issue. If you are on Linux you can also check the logs, for example:

tail -f /var/log/httpd/error.log

You may be able to track the error this way. Finally another option is to run the php file from the browser and check for output, then try from command line and again check for output. If you can nail down if under both instances there is an issue we would likely be closer to the solution.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.