1

I have just installed pdf2htmlEX without any issues. If I run the command on the server it works fine. So I know the library itself is doing what it is supposed to do. If I run the command in php via the exec function nothing happens. I assume exec is used in this instance??

In PHP

// doesn't work
$output = exec('pdf2htmlEX --zoom 1.3 pdf/test.pdf');
// doesn't work
$output = shell_exec('pdf2htmlEX --zoom 1.3 pdf/test.pdf');

If I run a general command in the exec function it works fine, so I know exec is enabled and working as expected.

// works fine
$exec =  exec('pwd', $output);
print_r($output);

Direct on Command Line not in PHP

// works and generates the file as expected.
pdf2htmlEX --zoom 1.3 pdf/test.pdf

Any help would be greatly appreciated.

Command line reference for library https://github.com/coolwanglu/pdf2htmlEX/wiki/Quick-Start

EDIT: After some further digging, it could be that the php script runs as a different user to the command line. My question would then be how do I check/fix this?

3 Answers 3

1

You just have to add the output html path and file name in your command :

Most of pdf_to_something packages usage with exec() is package_name [options] <input-filename> <output-filename>

$path = 'path/to/your/folder/';

$command = 'pdf2htmlEX '.$path.'test.pdf '.$path.'test.html';

exec($command);
Sign up to request clarification or add additional context in comments.

Comments

0

Try following and check if your file is created in working directory.

exec('pdf2htmlEX --zoom 1.3 pdf/test.pdf',$output);

1 Comment

Thanks, i tired this and it didn't work. I think it may be due to the php script being executed as a different user to the command line. The command line has permission and the script doesn't. Not sure how to fix though stackoverflow.com/questions/4411356/…
0

pdf2htmlEX doesn't output anything.

$cmd=  "pdf2htmlEX --zoom 1.3 test/test.pdf";
exec($cmd, $output);

Will create a test.html file in the current directory.

Are you expecting something else?

Note: i've tested this on ubuntu by installing pdf2htmlEX with

sudo apt-get install pdf2htmlex

To get the output,

$a = file_get_contents("test.html"); 
echo $a;

8 Comments

It's isn't outputting the file test.html when running the command in php, but does when run from the command prompt.
I've also ran it from a gnome-terminal and still no output. In both cases, the .html file was created. You can do a $a = file_get_contents("test.html"); echo $a; if you want to see it.
The file is never created when executed in php for me. I think it may be due to the php script being executed as a different user to the command line. The command line has permission and the script doesn't. Not sure how to fix though stackoverflow.com/questions/4411356/…
is your folder writeable? it needs to be. You can copy your php code in /tmp and test there.
The folder is set to 777
|

Your Answer

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