如何将多个文件夹中的pdf文件转换为与文件夹名称匹配的多个pdf文件


2

我有多个文件夹,每个文件夹包含多个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

Answers:


1

将文件夹中的PDF文件合并到一个匹配文件夹名称的PDF文件

由于您有将所有JPG文件转换为PDF文件的解决方案,因此您需要一种解决方案,将文件夹中的所有PDF文件合并为按文件名时间顺序合并的单个PDF文件。

您可以将PDFtk Free及其 CLI PDFtkcat批处理脚本中的参数一起使用,以自动执行操作,将文件夹中的所有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.

    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>]
    
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.