In the corporate sector, sometimes there is the task of automatically converting documents from one format to another, as well as the task of their software processing and modification. It would seem that the problem is: for normal formats, long-established full-featured libraries were written for work - so Perl or Python is up to you and forward.#!/bin/bash # # LibreOffice. # # : libre-converter.sh infile outfile LIBREOFFICE=`which libreoffice` PYTHON=`which python` DIR=`dirname "$0"` if [ ! -e "$1" ] then echo "Could not find source file $1" exit fi if [ ! -x "$LIBREOFFICE" ] then echo "Could not find LibreOffice binary" exit fi if [ ! -x "$PYTHON" ] then echo "Could not find Python" exit fi # LibreOffice killall -u `whoami` -q soffice # - LibreOffice API test -f $DIR/DocumentConverter.py || wget http://www.artofsolving.com/files/DocumentConverter.py # LibreOffice 8100 TCP $LIBREOFFICE "-accept=socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" -norestore -nofirststartwizard -nologo -headless & # , , LibreOffice sleep 5s # ... echo -n " Converting $1 to $2... " $PYTHON $DIR/DocumentConverter.py "$1" "$2" echo "Done!" # LibreOffice killall -u `whoami` soffice #!/bin/bash DIR=`dirname "$0"` TOOLS="$DIR/tools" INFILE="$1" FILENAME=`echo "$1" | sed 's/\.[^.]*$//'` SHORTNAME=`basename "$FILENAME"` OUTPATH=`dirname "$FILENAME"` if [ ! -e "$INFILE" ] then echo "Could not find source file $INFILE" exit fi echo "" echo "### Converting $INFILE ###" # DOC ODT: echo "1. Converting DOC to ODT:" $TOOLS/libre-converter.sh "$INFILE" "$FILENAME.odt" if [ $? -ne 0 ]; then echo "ERROR!" echo " $INFILE LibreOffice!" rm "$FILENAME.odt" exit fi # echo -n "2. Add first page to ODT... " $TOOLS/add-1st-page.pl "$FILENAME.odt" if [ $? -ne 0 ]; then echo "ERROR!" echo " $INFILE!" rm "$FILENAME.odt" exit fi echo "Done!"; # ODT PDF echo "3. Converting ODT to PDF:" $TOOLS/libre-converter.sh "$FILENAME.odt" "$OUTPATH/$SHORTNAME.pdf" if [ $? -ne 0 ]; then echo "ERROR!" echo " $FILENAME.odst LibreOffice!" rm "$FILENAME.odt" exit fi # echo -n "4. Do some cleaning... " rm "$FILENAME.odt" echo "All done! :)" find /my/doc/path -type f -iname "*.doc" -exec ./convert.sh {} \; convert sample.pdf sample.png convert sample.pdf sample.jpg convert sample.pdf sample.tif Source: https://habr.com/ru/post/97637/
All Articles