user5483305
user5483305

Reputation:

Running exec command php

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?

Upvotes: 1

Views: 724

Answers (3)

vhanahrni
vhanahrni

Reputation: 77

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

Upvotes: 1

Alex Tartan
Alex Tartan

Reputation: 6826

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;

Upvotes: 0

Code3d
Code3d

Reputation: 73

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

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

Upvotes: 0

Related Questions