Close Menu
    Facebook X (Twitter) Instagram Threads
    The Open Source Post
    • About
      • About FOSS Post
      • Donate
      • Privacy Policy
      • Services
    • Q&A
      • Take a Quiz
    • Linux
      • Ubuntu
    • AI
    • News
    • Statistics
    • Featured
      • Blog
    • How To
    • Software
    • Resources
      • Open Source Android Apps Series
    • Contact Us
    • Read More
      • Insights
    Facebook X (Twitter) YouTube
    The Open Source Post
    Home - Linux Desktop Tips & Tricks - How to Split PDF Files on Linux
    Linux

    How to Split PDF Files on Linux

    AudreyBy AudreyOctober 5, 2020Updated:May 21, 20261 Comment4 Mins Read489 Views

    The Linux command line is quite magical in that it can do wonders in a few lines of writing. Work which used to take hundreds of hours can be done easily using a one-line command or a Bash shell script.

    We would like to deal with PDFs today; As they are the default format for sharing documents and most people reading this article have probably used tons of them in their lives. We’ll show you how you can divide a large PDF file (say 500 pages) into much smaller PDF files (e.g. 100 PDF files where each one of them is 5 pages long).

    This could be useful for automation tasks or other types of use cases that may come to your mind where dealing with the original PDF is just not quite feasible.

    Getting the Shell Script

    First, you have to install pdftk, which is a well-known command line tool to work with PDF files on Linux and other Unix-like operating systems. You may grab it by searching for its name in your package repository, or simply installing it as a Snap package:

    sudo snap install pdftk

    The good-and-working Shell script to do the the job was actually provided as an answer to a Unix StackExchange question, by the user @Unlink. It simply takes two parameters named $pagesper (Number of pages in each PDF chunk you want) and $file (Name or path of the PDF file you want to target), and then just uses a while loop in Bash to invoke the pdftk command, that’s it.

    Here is the script:

    number=$(pdfinfo -- "$file" 2> /dev/null | awk '$1 == "Pages:" {print $2}')
    ​
    count=$((($number+$pagesper-1)/$pagesper))
    filename=${file%.pdf}
    ​
    counter=0
    while [ "$count" -gt "$counter" ]; do
     start=$((counter*pagesper + 1));
     end=$((start + pagesper - 1));
     if [ $end -gt $number ]; then
       end=$number
     fi
    ​
     counterstring=$(printf %01d "$counter")
    pdftk "$file" cat "${start}-${end}" output "${filename}_${counterstring}.pdf"
     counter=$((counter + 1))
    done

    Put it in your home folder (Or wherever you want to work with the PDF file) under the name pdfsplit.sh, and then make it executable with:

    chmod +x pdfsplit.sh

    Now we are ready to use the script.

    Dividing the PDF File into Smaller Chunks

    Simply run the Bash script using the following command:

    pagesper=5 file=my_large_file.pdf ./pdfsplit.sh

    Where 5 is the number of pages in each divided PDF file you want, and my_large_file.pdf is the name of the PDF file you want to divide (Must be of course in the same directory as the Shell script).

    And you’ll see how the smaller PDF files are generated:

    Each one of these files contains 5 pages as we requested.

    Other PDF Manipulation Possibilities

    You can use the pdftk command line without the script to do further manipulations with PDF files on Linux. Run pdftk --help to see its full documentation.

    You can for example divide the PDF file into smaller chunks where each new PDF file is just 1 page long using the following command (So that if you have 300 pages in the PDF, 300 smaller files will be generated where each one of them is 1 page long):

    pdftk my_large_file.pdf burst

    You may also extract specific ranges from the PDF file into smaller files (E.g you may just want pages 1-4, 8-12 and 16 from the PDF file and nothing else):

    pdftk A=my_large_file.pdf cat A1-4 A8-12 A16 output new_filename.pdf

    The new PDF will contain only the pages you specified in the range.

    Conclusion

    So as you have seen it may not take you 5 minutes of work to get this script kicking in order to manipulate your large PDF files however you like. All thanks to the Linux command line utilities like pdftk and the power of the Bash shell.

    If you have any further questions or additions on PDF manipulation on Linux, then we would love to have them in the comments section below.

    Linux Desktop Tips & Tricks
    Audrey

      Audrey specializes in writing about Linux distributions, open-source applications, developer tools, and emerging trends in the FOSS community. With a strong focus on accessibility and real-world usability, she delivers in-depth guides, thoughtful opinion pieces, and hands-on reviews for readers passionate about open-source software and digital freedom.

      Related Posts

      192 l.168.1.1 Admin Login

      May 29, 202612,701 Views

      Most Popular Linux Distros 2026: Market Share, User Base and Adoption Trends

      May 21, 20269,635 Views

      Top 7 Open Source CCTV/IP/Camera Monitoring Software

      August 8, 20245,537 Views

      Enable Zram on Linux For Better System Performance

      February 24, 20234,391 Views

      Make Your Linux Look Like Windows XP, 7 and 10

      March 26, 20203,948 Views
      The Open Source Post
      Facebook X (Twitter) YouTube
      • About
      • Privacy Policy
      • Take a Quiz
      • Write For Us
      • Services
      • Contact Us

      Type above and press Enter to search. Press Esc to cancel.