@echo on ::=========================================:: :: Textdoc to PDF Converter :: :: (text2pdf) :: ::=========================================:: :: :: :: Converts text documents to PDF :: :: using the OpenOffice macro interface. :: :: :: :: Requirements: OpenOffice and the :: :: necessary macro must be :: :: installed. :: :: :: :: License: Creative Commons :: :: Attribution Share-Alike :: :: :: ::=========================================:: :: janne.cederberg@gmail.com, 2008 :: ::=========================================:: :CONFIG set ENABLE_EXTENSION_CHECK=1 set USE_ONLY_ONE_OPENOFFICE_EXECUTION=1 set CONVERTABLE_EXTENSIONS=doc, dot, odt, psw, rtf, sdw, txt, wpd, wps rem set OPENOFFICE_SOFFICE_PATH="C:\Program Files\OpenOffice.org 2.4\program\soffice.exe" set OPENOFFICE_SOFFICE_PATH="C:\Program Files\OpenOffice.org 3\program\soffice.exe" set OPENOFFICE_MACRO_TO_USE=Standard.Module1.TextdocToPDF ::=====================================================================:: :: DON'T EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING :: ::=====================================================================:: :INIT set filelist= :: The following line is necessary for the for-loop under :PREPARE_CONVERSION_LIST :: to work correctly. For details, see: http://www.robvanderwoude.com/variableexpansion.html setlocal EnableDelayedExpansion :CHECK_IF_HELP_WANTED if "%~1"=="" goto HELP if "%~1"=="-h" goto HELP if "%~1"=="/h" goto HELP if "%~1"=="-?" goto HELP if "%~1"=="/?" goto HELP :START if not exist "%~f1" goto FILE_NOT_FOUND_ERROR goto CHECK_EXTENSION :CHECK_EXTENSION if "%ENABLE_EXTENSION_CHECK%"=="0" goto PREPARE_CONVERSION_LIST for %%i in (%CONVERTABLE_EXTENSIONS%) do ( if "%~x1"==".%%i" goto PREPARE_CONVERSION_LIST ) goto BAD_EXTENSION_ERROR :PREPARE_CONVERSION_LIST if "%USE_ONLY_ONE_OPENOFFICE_EXECUTION%"=="1" ( echo. echo Converting the following files to PDF: echo. ) for %%F in (%1) do ( if "%USE_ONLY_ONE_OPENOFFICE_EXECUTION%"=="1" ( echo - %%~F set filelist=!filelist!;%%~fF ) else ( title %%~F =^> %%~nF.pdf... echo Converting: %%~F =^> %%~nF.pdf start "" /wait %OPENOFFICE_SOFFICE_PATH% -invisible "macro:///%OPENOFFICE_MACRO_TO_USE%(%%~fF)" ) ) goto DO_WE_HAVE_MORE_PARAMS :BAD_EXTENSION_ERROR echo The conversion of files with the extension "%~x1" is not supported. goto DO_WE_HAVE_MORE_PARAMS :FILE_NOT_FOUND_ERROR echo The file "%~1" was not found. goto DO_WE_HAVE_MORE_PARAMS :DO_WE_HAVE_MORE_PARAMS if not "%2"=="" ( shift goto START ) if "%filelist%"=="" goto END if "%USE_ONLY_ONE_OPENOFFICE_EXECUTION%"=="1" goto DO_CONVERSION goto END :DO_CONVERSION :: remove the unnecessary ; from the beginning of the variable set filelist=%filelist:~1% title Converting files to PDF... ::start "" /wait %OPENOFFICE_SOFFICE_PATH% -invisible "macro:///%OPENOFFICE_MACRO_TO_USE%(%filelist%)" ::start "" /wait %OPENOFFICE_SOFFICE_PATH% "macro:///%OPENOFFICE_MACRO_TO_USE%(%filelist%)" start "" /wait %OPENOFFICE_SOFFICE_PATH% -norestore -nofirststartwizard -nologo -headless "macro:///%OPENOFFICE_MACRO_TO_USE%(%filelist%)" goto END :HELP echo. echo Converts the following file types to PDF: echo %CONVERTABLE_EXTENSIONS% echo. echo Syntax: echo %~n0 file1 [file2 [...]] Converts the listed files to PDF, echo wildcards are allowed. echo %~n0 /? Displays this help. echo %~n0 Displays this help. echo. echo Examples: echo %~n0 abc.odt def.doc Converts files abc.odt and def.doc. echo %~n0 myfile.txt *.rtf Converts the file myfile.txt and in echo addition all .rtf-files in the echo current folder. echo %~n0 aa*.doc b*c.odt Converts all .doc-files starting with aa echo and .odt-files starting with b, ending echo with c. echo %~n0 *.doc *.odt *.rtf Converts all files of the mentioned types echo in the current folder to PDF. echo Requirements: echo OpenOffice and within it the macro needed for doing the actual echo conversion processes must be installed. echo. goto TERMINATE :END title %ComSpec% endlocal echo. :TERMINATE