Skip to content

Instantly share code, notes, and snippets.

@johanjohan
Created February 22, 2019 15:16
Show Gist options
  • Save johanjohan/c46193d23f555252341322e0c932c26b to your computer and use it in GitHub Desktop.
Save johanjohan/c46193d23f555252341322e0c932c26b to your computer and use it in GitHub Desktop.
windows batch file to convert openoffice odt files into pdf
@ECHO OFF
REM convert a series of .odt first into .docx and then into .pdf
REM needs conversion to doc first, otherwise there are faulty expression errors
REM https://askubuntu.com/questions/60778/how-can-i-convert-an-odt-file-to-a-pdf
:: https://stackoverflow.com/questions/22211104/batch-file-will-not-run-as-administrator
echo(%cd%
pushd %~dp0
echo(%cd%
SET MASK_ODT=RE*.odt
rem SET MASK_ODT=RE201702_xxxx.odt
SET TMP_EXT=docx
SET TMP_MASK=RE*.%TMP_EXT%
REM SET EXE=soffice.exe
SET EXE=swriter.exe
SET "EXE_FULL_PATH=C:\Program Files\LibreOffice\program\%EXE%"
echo %EXE_FULL_PATH%
REM -----------odt to docx----------------------------------------------------
ECHO ...odt to %TMP_EXT%..............................
FOR %%i IN (%MASK_ODT%) DO (
ECHO %%i
"%EXE_FULL_PATH%" --headless --convert-to %TMP_EXT% %%i
)
REM -----------docx to pdf, remove docx-------------------------------------
ECHO
ECHO ...%TMP_EXT% to pdf..............................
FOR %%i IN (%TMP_MASK%) DO (
ECHO %%i
"%EXE_FULL_PATH%" --headless --convert-to pdf %%i
DEL %%i
)
REM ---------------------------------------------------------------
pause
EXIT /B 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment