我有多个文件夹,每个文件夹都包含多个pdf图像文件,如下所示:
Folder 1
file1.pdf
file2.pdf
file3.pdf
...
file100.pdf
Folder 2
file1.pdf
file2.pdf
file3.pdf
...
file100.pdf
Folder 3
file1.pdf
file2.pdf
file3.pdf
...
file100.pdf
...
Folder 94
file1.pdf
file2.pdf
file3.pdf
...
file100.pdf
有什么方法可以创建一种脚本,该脚本一次将每个文件夹输出为一个pdf文件,如下所示:
Folder1.pdf
Folder2.pdf
Folder3.pdf
...
Folder94.pdf
由于您具有将所有JPG文件转换为PDF文件的解决方案,因此需要一种解决方案,该解决方案将文件夹中的所有PDF文件合并为一个基于文件名按时间顺序合并的PDF文件。
您可以将PDFtk Free及其CLI PDFtk与cat
批处理脚本中的参数一起使用,以自动执行将文件夹内的所有PDF文件转换为以文件夹名作为文件名的单个PDF的操作。
“ PDFtk Free是我们友好的图形工具,可用于快速合并和拆分PDF文档和页面。只要您愿意,它就可以免费使用。”
“高级用户:PDFtk Free随我们的命令行工具PDFtk Server一起提供。因此,您既可以获取PDFtk的GUI也可以使用命令行界面!”
注意:该
SourceParentDir=
值将是您需要合并带有PDF文件的子文件夹所在位置的完整路径。
@ECHO OFF
SET "SourceParentDir=C:\Root\Parent\Folder"
FOR /R "%SourceParentDir%" %%A IN (.) DO (
IF /I NOT [%%~A]==[%SourceParentDir%\.] pdftk "%SourceParentDir%\%%~NA\*.pdf" cat output "%SourceParentDir%\%%~NA.pdf"
)
PAUSE
EXIT
@ECHO OFF
SET "SourceParentDir=C:\Root\Parent\Folder"
FOR /R "%SourceParentDir%" %%A IN (.) DO (
IF /I NOT [%%~A]==[%SourceParentDir%\.] pdftk "%SourceParentDir%\%%~NA\*.pdf" cat output "%SourceParentDir%\temp.pdf"
IF EXIST "%SourceParentDir%\temp.pdf" pdftk "%SourceParentDir%\temp.pdf" cat end-1 output "%SourceParentDir%\%%~NA.pdf"
IF EXIST "%SourceParentDir%\%%~NA.pdf" IF EXIST "%SourceParentDir%\temp.pdf" DEL /Q /F "%SourceParentDir%\temp.pdf"
)
PAUSE
EXIT
FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters] Walks the directory tree rooted at [drive:]path, executing the FOR statement in each directory of the tree. If no directory specification is specified after /R then the current directory is assumed. If set is just a single period (.) character then it will just enumerate the directory tree.
批量替换(FOR /?)
此外,FOR变量引用的替换已得到增强。现在,您可以使用以下可选语法:
%~nI - expands %I to a file name only
pdftk.exe --Help
cat [<page ranges>] Assembles (catenates) pages from input PDFs to create a new PDF. Use cat to merge PDF pages or to split PDF pages from documents. You can also use it to rotate PDF pages. Page order in the new PDF is specified by the order of the given page ranges. Page ranges are described like this: <input PDF handle>[<begin page number>[-<end page num- ber>[<qualifier>]]][<page rotation>]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句