批处理文件一个接一个地处理多个pdf然后删除它们

Batch File to process multiple pdfs one after another then delete them

我有一个批处理文件,它采用多页 pdf,然后将每一页转换为单独的 jpeg。这通过将 pdf 拖到批处理文件上来实现。我现在需要获取此批处理文件以搜索目录中的所有 pdf 并一次处理每一个,一旦过程完成就删除或移动源 pdf。这是到目前为止的批处理文件。 (我也在使用 Ghost 脚本库)

echo off
echo.
echo.

set DPI=300
set ALPHABITS=2
set QUALITY=95
set FIRSTPAGE=1
set LASTPAGE=9999
REM MEMORY in MB
set MEMORY=300

set PDFFILE=%1
set JPGFILE=%PDFFILE:.pdf=-%%%d.jpg

set GS=%2
IF "%GS%" == "" (
    set GS="bin/gswin32c.exe"
    echo Loaded in 32bit mode
    echo.
)

%GS% -sDEVICE=jpeg -sOutputFile=%JPGFILE% -r%DPI% -dNOPAUSE -dFirstPage=%FIRSTPAGE% -dLastPage=%LASTPAGE% -dJPEGQ=%QUALITY% -dGraphicsAlphaBits=%ALPHABITS%  -dTextAlphaBits=%ALPHABITS%  -dNumRenderingThreads=4 -dBufferSpace=%MEMORY%000000  -dBandBufferSpace=%MEMORY%000000 -c %MEMORY%000000 setvmthreshold -f %PDFFILE% -c quit


move *.jpg "C:\ProgramData\EFI\EFI eXpress\Work\JobFolder\"
echo Finished.
pause

我现在遇到这个错误

Error: /undefinedfilename in (Coffee)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1195/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.14 (2014-03-26)
Copyright (C) 2014 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefinedfilename in (Coffee)
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push
Dictionary stack:
   --dict:1195/1684(ro)(G)--   --dict:0/20(G)--   --dict:77/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
GPL Ghostscript 9.14 (2014-03-26)
Copyright (C) 2014 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Error: /undefinedfilename in (OF)

试试这个代码,它可能对你有用:

echo off
echo.
echo.

set DPI=300
set ALPHABITS=2
set QUALITY=95
set FIRSTPAGE=1
set LASTPAGE=9999
REM MEMORY in MB
set MEMORY=300

set JPGFILE=%PDFFILE:.pdf=-%%%d.jpg

set GS=%2
IF "%GS%" == "" (
    set GS="bin/gswin32c.exe"
    echo Loaded in 32bit mode
    echo.
)

for /f "delims=" %%a in ('dir /b *.pdf') do %GS% -sDEVICE=jpeg -sOutputFile=%JPGFILE% -r%DPI% -dNOPAUSE -dFirstPage=%FIRSTPAGE% -dLastPage=%LASTPAGE% -dJPEGQ=%QUALITY% -dGraphicsAlphaBits=%ALPHABITS%  -dTextAlphaBits=%ALPHABITS%  -dNumRenderingThreads=4 -dBufferSpace=%MEMORY%000000  -dBandBufferSpace=%MEMORY%000000 -c %MEMORY%000000 setvmthreshold -f %%a -c quit


move *.jpg "C:\ProgramData\EFI\EFI eXpress\Work\JobFolder\"
echo Finished.
pause

这应该有效 - 虽然 "%%~na.jpg""%%a" 这两个术语有双引号以允许长文件名,我只是假设可执行文件正确处理它们。

@echo off
echo.
echo.

set DPI=300
set ALPHABITS=2
set QUALITY=95
set FIRSTPAGE=1
set LASTPAGE=9999
REM MEMORY in MB
set MEMORY=300

set GS=%2
IF "%GS%" == "" (
    set GS="bin/gswin32c.exe"
    echo Loaded in 32bit mode
    echo.
)

md "done" 2>nul

for %%a in (*.pdf) do (

%GS% -sDEVICE=jpeg -sOutputFile="%%~na.jpg" -r%DPI% -dNOPAUSE -dFirstPage=%FIRSTPAGE% -dLastPage=%LASTPAGE% -dJPEGQ=%QUALITY% -dGraphicsAlphaBits=%ALPHABITS%  -dTextAlphaBits=%ALPHABITS%  -dNumRenderingThreads=4 -dBufferSpace=%MEMORY%000000  -dBandBufferSpace=%MEMORY%000000 -c %MEMORY%000000 setvmthreshold -f "%%a" -c quit

move "%%a" "done"
)

move *.jpg "C:\ProgramData\EFI\EFI eXpress\Work\JobFolder\"
echo Finished.
pause