批量检查文件大小,然后再继续打印 [英] Batch to check file size before proceed to printing

查看:81
本文介绍了批量检查文件大小,然后再继续打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该批次当前用于从网站打印我们的每日报告,然后将其另存为pdf(作为备份)并打印一份纸质副本.
在保存pdf的过程中,每天会生成2种不同大小的pdf文件(仅1天1 pdf).某些pdf的大小将超过20kb,其中包含我们的每日报告,而某些pdf的大小将在9kb(8485字节)左右(空报告,因为那天没有销售).
我现在的目标是通过防止那些空报告来节省纸张,这一天将不会打印出来.因此,如何在当前代码中添加一些代码,以便在打印之前,批处理将在进行打印之前检查文件大小.如果可能的话,我也想创建一个msgbox,以便在由于报告为空而无法打印pdf时提示用户.

This batch currently im using to print our daily report from a website then saved it as pdf (as a backup) and print one hard copy.
During saving the pdf, there will be 2 different size of pdf files generated daily(1 day 1 pdf only). Size of some pdf will be more than 20kb which contain our daily report and some will be around 9kb (8485bytes) (empty report because that day no sales).
My target now to save paper by preventing those empty report will not be print on that day. So how to add some code into my current code so that before printing, batch will check for file size before go to printing job. If possible, I want to create a msgbox too so that user will be prompt when no pdf will be print because of report empty.

请参阅下面的代码:

  1. 设置日期参数
  2. 创建文件夹和子文件夹
  3. 使用wkhtmltopdf将网页转换为PDF
  4. 在打印之前检查文件大小 这就是我要添加的内容.如果生成的pdf大小超过9kb,则自动进入第5号和第6号.否则,使用msgbox提示用户今天没有报告,请按OK关闭计算机"
  5. 打印
  6. 关闭计算机
  1. Setting date parameter
  2. Creating folder and subfolders
  3. Using wkhtmltopdf to webpage to PDF
  4. Check file size before printing This is what I want to add. If generated pdf size more that 9kb, proceed to No 5 and No 6 automatically. Else, prompt user using msgbox "No report for today, Press OK to shutdown computer"
  5. Printing
  6. Shutting down computer


@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

推荐答案

下面是一个示例

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆