First, you should read this stackoverflow post
The instructions below are slightly modified to a specific project where we're converting every document to PDF
- Create the
/usr/local/bin/unoconv.sh
file by doing:sudo touch /usr/local/bin/unoconv.sh
- Give the file executable permissions:
sudo chmod +x /usr/local/bin/unoconv.sh
- Copy and paste this code into your
unoconv.sh
file
#!/bin/bash
if [ -z "$1" ]; then
echo "Must pass source file to convert to pdf";
exit 10;
fi
# This assumes your unoconv executable is located at /usr/bin/unoconv
# If that's not true try a `which unoconv` to get the path and update
# the path below to your path
/usr/bin/unoconv -f pdf $1
Run sudo visudo
to edit the /etc/sudoers
file and add the following two lines to the bottom
# /etc/sudoers
# ... stuff ...
# Give apache sudo privileges to run /usr/local/bin/unoconv.sh script
www-data ALL=NOPASSWD: /usr/local/bin/unoconv.sh
In your web root, create a file called test_unoconv.php
<?php
# Provide the full filepath to a document you want converted into a PDF
$file = "/path/to/your/xlsfile.xls";
echo "Running: 'sudo /usr/local/bin/unoconv.sh {$file}'";
shell_exec('sudo /usr/local/bin/unoconv.sh ' . $file);
In your browser, go to your test script (i.e., http://example.com/test_unoconv.php) and watch the original directory of the file to see if a new PDF was created. If everything worked, you should have a PDF with the same filename as the original source document
thanks!!! i already fix my problem from this post!!!