Skip to content

Commit b7c6d8a

Browse files
committed
Improving the batch_PDF_compressor installation process and Ghostscript validation
1 parent c5f16d6 commit b7c6d8a

File tree

12 files changed

+55
-38
lines changed

12 files changed

+55
-38
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The script offers the following features:
4242
3. Select the directory containing the PDF files you want to compress. The script will "look" at the lower levels and process the PDFs in the subdirectories on its own.
4343
4. Select the compression level (1-4) corresponding to the provided options.
4444
5. Choose whether to delete or keep the original PDF files.
45-
6. After completion you can find the a log file containing information about processed files and compression results at `%UserProfile%\Documents` with the name `batch_PDF_compressor_log.txt`.
45+
6. After completion you can find the a log file containing information about processed files and compression results at `%UserProfile%\Documents` with the name `batch_PDF_compressor.log`.
4646

4747
![image](https://github.com/sergeiown/batch_PDF_compressor/assets/112722061/8c874426-ffab-4d7e-8749-0e70e52fbdb2)
4848

batch_PDF_compressor.bat

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,78 @@
1-
@REM Batch PDF compressor is a Windows batch process file written in the Batch command language.
2-
@REM It utilizes the [Ghostscript](https://www.ghostscript.com/) to perform operations on PDF files.
1+
@REM ========================================================================
2+
@REM Batch PDF Compressor
3+
@REM A Windows batch script for compressing PDF files using Ghostscript.
4+
@REM [Ghostscript](https://www.ghostscript.com/)
35
@REM [Copyright (c) 2023 - 2024 Serhii I. Myshko](https://github.com/sergeiown/compress_PDF/blob/main/LICENSE.md)
6+
@REM ========================================================================
47

58
@echo off
6-
title Batch PDF compressor
9+
title Batch PDF Compressor
710
color 1F
8-
mode con: cols=105
9-
10-
set "outputFile=%USERPROFILE%\documents\batch_PDF_compressor_log.txt"
1111

12+
@REM ========================================================================
13+
@REM Initialize log file and start time
14+
@REM ========================================================================
15+
set "outputFile=%USERPROFILE%\documents\batch_PDF_compressor.log"
1216
call modules/date_time.bat
1317

1418
echo Start time: %day%.%month%.%year% %hour%:%minute%:%second% > %outputFile%
1519
echo. >> %outputFile%
1620
echo Log file path: %outputFile% >> %outputFile%
1721
echo. >> %outputFile%
1822

23+
@REM ========================================================================
24+
@REM Language Selection
25+
@REM ========================================================================
1926
call modules/language.bat
2027

2128
@REM Test script with manual language selection
29+
@REM Uncomment the line below to enable manual language testing
2230
@REM call tests/language_manual.bat
2331

32+
@REM ========================================================================
33+
@REM Ghostscript Module - Check if Ghostscript is available | install
34+
@REM ========================================================================
2435
setlocal enabledelayedexpansion
25-
2636
call modules/ghostscript.bat
2737
if "%exitScript%"=="1" (exit /b)
2838

39+
@REM ========================================================================
40+
@REM Directory Setup
41+
@REM ========================================================================
2942
call modules/directory.bat
3043
if "%exitScript%"=="1" (exit /b)
3144

45+
@REM ========================================================================
46+
@REM Compression Options Setup
47+
@REM ========================================================================
3248
call modules/options.bat
3349

50+
@REM ========================================================================
51+
@REM PDF Compression Execution
52+
@REM ========================================================================
3453
call modules/compression.bat
3554

55+
@REM ========================================================================
56+
@REM Post-Processing Information Display
57+
@REM ========================================================================
3658
call modules/information.bat
3759

60+
@REM ========================================================================
61+
@REM Log the finish time and copyright information
62+
@REM ========================================================================
3863
call modules/date_time.bat
3964

4065
echo. >> %outputFile%
4166
echo Finish time: %day%.%month%.%year% %hour%:%minute%:%second% >> %outputFile%
4267
echo. & echo. >> %outputFile%
68+
echo Log file: %outputFile%
69+
echo. & echo. >> %outputFile%
4370
echo Copyright (c) 2024 Serhii I. Myshko
4471
echo %copyright_link% >> %outputFile%
4572
echo. & echo. >> %outputFile%
46-
pause
73+
74+
@REM ========================================================================
75+
@REM End of script
76+
@REM ========================================================================
77+
pause
78+
exit

installer.iss

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#define MyAppName "Batch PDF Compressor"
2-
#define MyAppVersion "1.4"
2+
#define MyAppVersion "1.5"
33
#define MyAppPublisher "Serhii I. Myshko"
44
#define MyAppURL "https://github.com/sergeiown/batch_PDF_compressor"
55
#define MyAppExeName "batch_PDF_compressor.bat"
@@ -57,9 +57,6 @@ Name: "{userstartmenu}\Batch PDF compressor\{cm:UninstallProgram,{#MyAppName}}";
5757

5858
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; IconFilename: "{app}\batch_PDF_compressor.ico"; Tasks: desktopicon
5959

60-
[Run]
61-
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
62-
6360
[Uninstall]
6461
DisplayName={#MyAppName}
6562
AppId={{E714ADFC-E269-465D-9ED7-B54959018F8E}

messages/messages_english.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ msg_38=Your system is 32-bit.
3939
msg_39=Downloading information about the latest release...
4040
msg_40=Unable to get information about the latest release from GitHub.
4141
msg_41=JSON file not found or not loaded.
42-
msg_42=Information has been successfully uploaded:
42+
msg_42=Information has been successfully uploaded.
4343
msg_43=Finding an installer for the 64-bit version...
4444
msg_44=Finding an installer for the 32-bit version...
4545
msg_45=Found installer line:
@@ -49,7 +49,7 @@ msg_48=Downloading the installer...
4949
msg_49=Ghostscript installer has been downloaded successfully.
5050
msg_50=Ghostscript installer has been launched successfully.
5151
msg_51=Downloading the installer failed.
52-
msg_52=Attempting to install
52+
msg_52=Checking the installation...
5353
copyright_link=https://github.com/sergeiown/compress_PDF/blob/main/LICENSE.md
5454
ghostscript_link=https://ghostscript.com/releases/gsdnld.html
5555
ghostscript_altlink=https://github.com/ArtifexSoftware/ghostpdl-downloads/releases

messages/messages_russian.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ msg_38=Ваша система 32-разрядная.
3939
msg_39=Загрузка информации о последнем выпуске...
4040
msg_40=Невозможно получить информацию о последнем выпуске с GitHub.
4141
msg_41=JSON-файл не найден или не загружен.
42-
msg_42=Информация успешно загружена:
42+
msg_42=Информация успешно загружена.
4343
msg_43=Поиск программы установки для 64-битной версии...
4444
msg_44=Поиск программы установки для 32-битной версии...
4545
msg_45=Найдена строка установщика:
@@ -49,7 +49,7 @@ msg_48=Загрузка программы установки...
4949
msg_49=Установщик Ghostscript успешно загружен.
5050
msg_50=Установщик Ghostscript успешно запущен.
5151
msg_51=Загрузка программы установки не удалась.
52-
msg_52=Попытка установки
52+
msg_52=Проверка установки...
5353
copyright_link=https://github.com/sergeiown/compress_PDF/blob/main/LICENSE.md
5454
ghostscript_link=https://ghostscript.com/releases/gsdnld.html
5555
ghostscript_altlink=https://github.com/ArtifexSoftware/ghostpdl-downloads/releases

messages/messages_ukrainian.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ msg_38=Ваша система 32-розрядна.
3939
msg_39=Завантажуємо інформацію про останній випуск...
4040
msg_40=Не вдається отримати інформацію про останній випуск з GitHub.
4141
msg_41=JSON файл не знайдено або не завантажено.
42-
msg_42=Інформацію успішно завантажено:
42+
msg_42=Інформацію успішно завантажено.
4343
msg_43=Пошук інсталятора для 64-бітної версії...
4444
msg_44=Пошук інсталятора для 32-бітної версії...
4545
msg_45=Знайдено рядок інсталятора:
@@ -49,7 +49,7 @@ msg_48=Завантаження інсталятора...
4949
msg_49=Інсталятор Ghostscript успішно завантажено.
5050
msg_50=Інсталятор Ghostscript успішно запущено.
5151
msg_51=Не вдалося завантажити інсталятор.
52-
msg_52=Спроба встановлення
52+
msg_52=Перевірка установки...
5353
copyright_link=https://github.com/sergeiown/compress_PDF/blob/main/LICENSE.md
5454
ghostscript_link=https://ghostscript.com/releases/gsdnld.html
5555
ghostscript_altlink=https://github.com/ArtifexSoftware/ghostpdl-downloads/releases

modules/directory.bat

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
@echo off
44

5-
@REM Select a directory using the FolderBrowserDialog
65
set "maxAttempts=3"
76
set "attempt=1"
87
:input_path
@@ -16,7 +15,6 @@ echo %directory% & echo %msg_26% %directory% >> %outputFile%
1615
echo. >> %outputFile%
1716
timeout /t 1 >nul
1817

19-
@REM Check if the directory exists for three times
2018
if not exist "%directory%" (
2119
echo %msg_25% & echo %msg_25% >> %outputFile%
2220
if %attempt% lss %maxAttempts% (

modules/ghostscript.bat

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
@echo off
44

5+
:check_again
56
set "gsRootPath64=%ProgramFiles%\gs"
67
set "gsRootPath32=%ProgramFiles(x86)%\gs"
78
set "gsExecutable="
8-
set "attempt=1"
99

10-
:check
1110
for /d %%D in ("%gsRootPath64%\gs*") do (
1211
if exist "%%D\bin\gswin64c.exe" (
1312
set "gsExecutable=%%D\bin\gswin64c.exe"
@@ -47,13 +46,13 @@ timeout /t 2 >nul
4746

4847
call modules/installer.bat
4948

50-
echo %msg_52% (%attempt%) & echo %msg_52% (%attempt%) >> %outputFile%
49+
echo %msg_52% & echo %msg_52% >> %outputFile%
5150
echo %error_separator% & echo %error_separator% >> %outputFile%
5251

53-
if "%exitScript%"=="0" if %attempt% lss 2 (
54-
set /a attempt+=1
55-
timeout /t 2 >nul
56-
cls & goto check
52+
if "%exitScript%"=="0" (
53+
timeout /t 5 >nul
54+
cls
55+
goto check_again
5756
) else (
5857
cls & title = Batch PDF compressor
5958
color 1C

modules/information.bat

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
@echo off
44

5-
@REM Display and log a message block with information about the compression process
65
cls
76
color 1E
87
echo %double_separator% & echo %double_separator% >> %outputFile%
@@ -12,7 +11,6 @@ echo. & echo. >> %outputFile%
1211
echo %double_separator% & echo %double_separator% >> %outputFile%
1312
timeout /t 1 >nul
1413

15-
@REM Information about the number of files
1614
echo. & echo. >> %outputFile%
1715
echo %msg_19% !progress! & echo %msg_19% !progress! >> %outputFile%
1816
echo. & echo. >> %outputFile%
@@ -24,7 +22,6 @@ echo %msg_28% !progress_error! & echo %msg_28% !progress_error! >> %outputFile%
2422
echo. & echo. >> %outputFile%
2523
echo %long_separator% & echo %long_separator% >> %outputFile%
2624

27-
@REM Information about the size and percentage of compression
2825
echo. & echo. >> %outputFile%
2926
echo %msg_22% %initialSizeKB%.%initialSizeKB:~-2% KB & echo %msg_22% %initialSizeKB%.%initialSizeKB:~-2% KB >> %outputFile%
3027
echo. & echo. >> %outputFile%

modules/installer.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if not exist "%jsonFile%" (
3131
exit /b
3232
)
3333

34-
echo %msg_42% %jsonFile% & echo %msg_42% %jsonFile% >> %outputFile%
34+
echo %msg_42% & echo %msg_42% >> %outputFile%
3535

3636
set "installerFound=0"
3737
if "%is64Bit%"=="1" (

0 commit comments

Comments
 (0)