📅  最后修改于: 2023-12-03 14:43:54.956000             🧑  作者: Mango
PDF is a popular format for documents, but sometimes we might need to extract certain pages or split the PDF into multiple documents. Linux command line provides a powerful tool called "pdftk" which allows us to do these tasks easily. In this tutorial, we will learn how to use "pdftk" to convert and split PDF files in Linux using the Shell-Bash.
Before we start using "pdftk", we need to install it on our Linux system. We can use the following command to install "pdftk" on Ubuntu and Debian-based systems:
sudo apt-get install pdftk
For other Linux distributions, we can download the package from the official website and install it manually.
To extract specific pages from a PDF file, we can use the following command:
pdftk input.pdf cat <pages> output output.pdf
In the above command, "input.pdf" is the name of the input PDF file,
pdftk input.pdf cat 1,3,5 output output.pdf
To split a PDF file into multiple documents, we can use the following command:
pdftk input.pdf burst output output_%04d.pdf
In the above command, "input.pdf" is the name of the input PDF file, and "output_%04d.pdf" is the format of the output file. The "%04d" is a placeholder for the page number, and it ensures that the files are named in a sequential order. For example, if the input PDF file has 10 pages, this command will create 10 output files named output_0001.pdf, output_0002.pdf, and so on.
The "pdftk" command-line tool is a very useful tool for handling PDF files in Linux. In this tutorial, we learned how to extract specific pages from a PDF file and split a PDF file into multiple documents using "pdftk". With the knowledge gained from this tutorial, you should be able to work with PDF files efficiently in your Linux system.