Search code examples
pdfghostscript

Ghostscript PDF combine file limit?


If I have a bat file on windows to drive ghostscript PDF combine like:

C:\Program Files (x86)\GPLGS>gswin32c.exe -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=c:\copyfolder\combine.pdf -dBATCH c:\copyfolder\AgentLetter.pdf c:\copyfolder\iso.pdf c:\copyfolder\disclosure.pdf

In the above example I am combining 3 files. Is there a limit to the number of files I can list to be combined ?

Thanks

I just tried a test combining 3 files and it works. Wondering if there is a limit on number of files I can combine at once ?


Solution

  • The use of CLI programming is sometimes discouraged but is the basis of all top level machine OS code just same as running Pythonic Wheels or powershell instructions or scraping web pages, the aim is to do as much programatically in one line of instruction so as to be modular in computer applications.

    [Edit] As mentioned by KenS in comment use a @filelist (TL;DR its at the end) or for single command line usage you can shorten the total string length.

    You will find on Windows it is the string length of a CMD console is the limit so abbreviate the programming commands as much as possible

    traditionally you could rename the exe to same as Unix and use newer -o for output and keep names short without paths would go further to help

    >gs -q -sDEVICE=pdfwrite -ocombine.pdf 01.pdf 02.pdf 03.pdf
    

    example

    >gs.exe -q -sDEVICE=pdfwrite -ocombine.pdf 01.pdf 02.pdf 03.pdf
    
    C:\Apps\PDF\GS\gs1000w64\bin>dir 0*.pdf
     Directory of C:\Apps\PDF\GS\gs1000w64\bin
    01/02/2023  19:23         2,821,328 01.pdf
    01/02/2023  19:23         2,821,328 02.pdf
    01/02/2023  19:23         2,821,328 03.pdf
                   3 File(s)      8,463,984 bytes
    
    C:\Apps\PDF\GS\gs1000w64\bin>dir co*.pdf
     Directory of C:\Apps\PDF\GS\gs1000w64\bin
    17/02/2023  16:32         2,831,780 combine.pdf
    

    amazing the 27 page file is not much bigger than 1 of 9 pages, but I cheated they are the same file, thus same fonts.

    if really string is an issue GS does not need .pdf simply .p will do but for windows sake use at least one letter as extension.

    C:\bin>gs -q -sDEVICE=pdfwrite -oALL.pdf 01.p 02.p 03.p
    

    using

    "path\gswin##c.exe" "path to\@filesmerge.txt"
    

    commands as program instructions are strung out vertically but any filename with spaces needs "quot ing"

    filesmerge.txt

    -sDEVICE=pdfwrite
    -oALL.pdf
    "C:\Any where with\a long name.pdf"
    C:\Data\somewhere\blank.pdf
    "C:\Data\some where\c me c you.pdf"
    "C:\Data\some where else\done.pdf"
    

    You can mix and match so if just the filesnames to merge are listed you can run

    "C:\Apps\PDF\GS\gs1000w64\bin\gswin64c.exe" -sDEVICE=pdfwrite -o"c:\data\all my.pdf" "@C:\source folder\filenames.txt"