在继续打印之前批量检查文件大小

Batch to check file size before proceed to printing

这批目前用于从网站打印我们的每日报告,然后将其保存为 pdf(作为备份)并打印一份硬拷贝。
在保存 pdf 期间,每天会生成 2 个不同大小的 pdf 文件(仅 1 天 1 个 pdf)。一些 pdf 的大小将超过 20kb,其中包含我们的每日报告,一些将约为 9kb(8485 字节)(空报告,因为那天没有销售)。
我现在的目标是通过防止当天不打印那些空报告来节省纸张。那么如何将一些代码添加到我当前的代码中,以便在打印之前,批处理将在打印作业之前检查文件大小。如果可能的话,我也想创建一个消息框,以便在由于报告为空而无法打印 pdf 时提示用户。

参考以下代码:

  1. 设置日期参数
  2. 正在创建文件夹和子文件夹
  3. 使用wkhtmltopdf将网页转PDF
  4. 打印前检查文件大小 这就是我要补充的。如果生成的 pdf 大小超过 9kb,则自动进行第 5 步和第 6 步。否则,使用 msgbox "No report for today, Press OK to shutdown computer"
  5. 提示用户
  6. 打印
  7. 正在关闭计算机

@echo off
title Daily Report to PDF

REM     ---------------------------------------------------------------------------
REM 1. Setting date parameter

for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set date=%%a
set month=%date:~4,2%
if %month%==01 set monthname=January
if %month%==02 set monthname=Febuary
if %month%==03 set monthname=March
if %month%==04 set monthname=April
if %month%==05 set monthname=May
if %month%==06 set monthname=June
if %month%==07 set monthname=July
if %month%==08 set monthname=August
if %month%==09 set monthname=September
if %month%==10 set monthname=October
if %month%==11 set monthname=November
if %month%==12 set monthname=December

for /f %%i in ('wmic path win32_localtime get dayofweek ^| findstr [0-9]') do set dayofweek=%%i
if %dayofweek%==1 set dow=(Mon)
if %dayofweek%==2 set dow=(Tue)
if %dayofweek%==3 set dow=(Wed)
if %dayofweek%==4 set dow=(Thu)
if %dayofweek%==5 set dow=(Fri)
if %dayofweek%==6 set dow=(Sat)
if %dayofweek%==7 set dow=(Sun)

REM     ---------------------------------------------------------------------------
REM 2. Creating folder and subfolders

set dir1="%USERPROFILE%\Desktop\TEST"
set day=%date:~6,2%
set months=%monthname:~0,3%
set year=%date:~0,4%
set fulldate=%day%%months%%year%%dow%

md %dir1%\"YEAR %year%"\%monthname% 2>NUL
cd %dir1%\"YEAR %year%"\%monthname%\ 
md a b c 2>NUL

REM ---------------------------------------------------------------------------
REM 3. Using wkhtmltopdf to webpage to PDF

set dir2="%USERPROFILE%\Desktop\TEST\YEAR %year%\%monthname%"
echo.
echo Saving report as %fulldate%.pdf
wkhtmltopdf -q -g https://www.google.com %dir2%\c\%fulldate%.pdf
echo.

REM     ---------------------------------------------------------------------------
REM 4. Check file size before printing

REM     ---------------------------------------------------------------------------
REM 5. Printing

echo Printing %fulldate%.pdf
echo.
echo "C:\Program Files (x86)\Foxit Software\Foxit Reader\Foxit Reader.exe" /t %dir2%\c\%fulldate%.pdf

REM ---------------------------------------------------------------------------
REM 6. Shutting down computer

shutdown -s  -t 60 -c
PAUSE
::EXIT

这是一个示例 ,它试图模仿您发布的示例并包含一些更改,主要是 Set 日期变量。

@Echo Off
Title Daily Report to PDF

Rem     ------------------------------------------------------------------------
Rem 1. Setting date variables

Set "_WeekDays=Sunday Monday Tuesday Wednesday Thursday Friday Saturday"
For /F %%A In ('WMIC Path Win32_LocalTime Get /Value^
 ^|FindStr "[0-9]$"')Do Set "_%%A"
For /F "Tokens=1%_DayOfWeek%" %%A In (". . . . . . . . . %_WeekDays%"
)Do Set "_DayFullName=%%A"
Set "_DayShortName=%_DayFullName:~,3%"
For %%A In (Day Hour Minute Month Second
)Do Call Set "_%%A=0%%_%%A%%" & Call Set "_%%A=%%_%%A:~-2%%"
For %%A In (January.01 February.02 March.03 April.04 May.05 June.06
    July.07 August.08 September.09 October.10 November.11 December.12
)Do If ".%_Month%"=="%%~xA" Set "_MonthFullName=%%~nA"
Set "_MonthShortName=%_MonthFullName:~,3%"
Set "_FullDateString=%_Day%%_MonthShortName%%_Year%%_DayShortName%"

Rem     ------------------------------------------------------------------------
Rem 2. Creating folder and subfolders

Set "_Dir1=%UserProfile%\Desktop\TEST\YEAR %_Year%\%_MonthFullName%"

For %%A In (a b c)Do MD "%_Dir1%\%%A" 2>NUL

Rem     ------------------------------------------------------------------------
Rem 3. Using wkhtmltopdf to convert webpage to PDF

Echo=
Echo Saving report as %_FullDateString%.pdf
wkhtmltopdf -q -g https://www.google.com "%_Dir1%\c\%_FullDateString%.pdf"
Echo=

Rem     ------------------------------------------------------------------------
Rem 4. Printing files with sizes over 8485 bytes

Set "_Exe1=%ProgramFiles(x86)%\Foxit Software\Foxit Reader\Foxit Reader.exe"

For %%A In ("%_Dir1%\c\%_FullDateString%.pdf")Do If %%~zA GTR 8485 (
    Echo Printing %%A&Echo=&"%_Exe1%" /t "%_Dir1%\c\%_FullDateString%.pdf")

Rem     ------------------------------------------------------------------------
Rem 5. Shutting down computer

ShutDown /S /T 60

注意:此脚本假定可执行文件 wkhtmltopdf 能够在批处理脚本为 运行 时从当前目录 运行。