Linux pdf save pages

HowTo: Split PDF File – Linux Command Line

Sometimes it is required to extract some pages from a PDF file and save them as another PDF document.

In Linux we can easily split PDF documents by pages using the command line utility called pdftk .

From this article you will learn how to extract individual pages or a range of pages from a PDF file and save them as another PDF document.

Cool Tip: Plan to send this PDF somewhere or just keep? How about to protect it with a password? This is really easy for ones who split PDF files from the command line! Read more →

First of all it is required to install the pdftk utility:

$ sudo apt-get install pdftk

Split PDF File

Extract the 5th page from the ORIG_FILE.pdf and save it to the NEW_FILE.pdf :

$ pdftk ORIG_FILE.pdf cat 5 output NEW_FILE.pdf

Extract several individual pages:

$ pdftk ORIG_FILE.pdf cat 1 4 6 output NEW_FILE.pdf

Cool Tip: Merge PDF files in Linux using the ghostscript command! Read more →

$ pdftk ORIG_FILE.pdf cat 1-5 output NEW_FILE.pdf

Extract the combination of individual pages and a range of pages:

$ pdftk ORIG_FILE.pdf cat 1 5 7 10-12 output NEW_FILE.pdf

4 Replies to “HowTo: Split PDF File – Linux Command Line”

Thanks for your excellent tip. I managed to change one of the commands a bit and thought it would be useful to share it here.
My requirement was to extract all pages of a pdf file to seperate pdf files, one per page. This can be achieved as follows (The `seq -w 10` gives a sequence from 1 to 10 with leading zeros, replace 10 with the number of pages in the scan.pdf file):
for i in `seq -w 10`; do pdftk scan.pdf cat $i output scan_$i.pdf; done

This is a great little script, and thanks for the heads up on the seq command. But use the burst option instead of cat and pdftk will do this for you. ” burst Splits a single input PDF document into individual pages. Also creates a report named doc_data.txt which is the same as the output from dump_data. If the output section is omitted, then PDF pages are named: pg_%04d.pdf, e.g.: pg_0001.pdf, pg_0002.pdf, etc.”

You’re not really extracting, you’re copy pages from one pdf to another. There is a difference. Extract mean to remove. Also a strange behavior: Extract 1/2 A.pdf to B.pdf and 1/2 A.pdf to C.pdf you wind up with B+C>A. There’s got to be a better solution.

Источник

How to extract pages from a PDF in Linux

If you are a keen book reader, it would be quite difficult for you to carry even more than two books. That’s no more the case, thanks to ebooks that save a lot of space in your home and your bag as well. Carrying hundreds of books with you is literally no more a dream.

Ebooks come in different formats, but the common one is PDF. Most of the ebook PDFs have hundreds of pages, and just like real books, with the help of a PDF reader navigating these pages is quite easy.

Читайте также:  Команды восстановления файловый системы linux

Suppose you are reading a PDF file and want to extract some specific pages from it and save it as a separate file; how would you do that? Well, it is a cinch! No need to get premium applications and tools to accomplish it.

This guide focuses on extracting a specific part from any PDF file and saving it with a different name in Linux. Though there are multiple ways to do this, I will be focusing on the less cluttered approach. So, let’s begin:

There are two main approaches:

You can follow any method according to your convenience.

How to extract PDF pages in Linux via GUI:

This method is more like a trick for extracting pages from a PDF file. Most of the Linux distributions come with a PDF reader. So, let’s learn a step by step process of extracting pages using the default PDF reader of Ubuntu:\

Step 1:

Simply open your PDF file in the PDF reader. Now click on the menu button and as shown in the following image:

Step 2:

A menu will appear; now click on the “Print” button, a window will come out with print options. You can also use the shortcut keys “ctrl+p” to quickly get this window:

Step 3:

To extract pages in a separate file, click on the “File” option, a window will open, give the file name, and select a location to save it:

I am selecting “Documents” as the destination location:

Step 4:

These three output formats PDF, SVG, and Postscript check PDF:

Step 5:

In the “Range” section, check the “Pages” option and set the range of page numbers you want to extract. I am extracting the first five pages so that I would type “1-5”.

You can also extract any page from the PDF file by typing the page number and separating it by a comma. I am extracting pages number 10 and 11 along with a range for the first five pages.

Note that the page numbers I am typing are according to the PDF reader, not the book. Ensure that you enter the page numbers that the PDF reader indicates.

Step 6:

Once all the settings are done, click on the “Print” button, the file will be saved in the specified location:

How to extract PDF pages in Linux via terminal:

Many Linux users prefer to work with the terminal, but can you extract PDF pages from the terminal? Absolutely! It can be done; all you need a tool to install called PDFtk. To get PDFtk on Debian and Ubuntu, use the command given below:

PDFtk can also be installed through snap:

Now, follow the below-mentioned syntax to use PDFtk tool for extracting pages from a PDF file:

  • [sample.pdf] – Replace it with the file name from where you want to extract pages.
  • [page_numbers] – Replace it with the range of page numbers, for example, “3-8”.
  • [output_file_name.pdf] – Type the name of the output file of extracted pages.

Let’s understand it with an example:

$pdftk adv_bash_scripting.pdf cat 3 — 8 output

In the above command, I am extracting 6 pages (3 – 8) from a file “adv_bash_scripting.pdf” and saving extracted pages by the name of “extracted_adv_bash_scripting.pdf.” The extracted file will be saved in the same directory.

If you need to extract a specific page, then type the page number and separate them by a “space”:

$pdftk adv_bash_scripting.pdf cat 5 9 11 output

Читайте также:  Linux содержимое какого файла обычно изменяет утилита passwd

In the above command, I am extracting page numbers 5, 9, and 11 and saving them as “extracted_adv_bash_scripting_2”.

Conclusion:

You may occasionally need to extract some specific portion of a PDF file for several purposes. There are many ways to do it. Some are complex, and some are obsolete. This write-up is about how to extract pages from a PDF file in Linux through two simple methods.

The first method is a trick to extract a certain part of a PDF through Ubuntu’s default PDF reader. The second method is via terminal since many geeks prefer it. I used a tool called PDFtk to extract pages from a pdf file through the use of commands. Both methods are simple; you can choose any according to your convenience.

About the author

Sam U

I am a professional graphics designer with over 6 years of experience. Currently doing research in virtual reality, augmented reality and mixed reality.
I hardly watch movies but love to read tech related books and articles.

Источник

Extract pages from PDF in Linux

Dealing with PDF files can be quite a hassle at times since they are not very modifiable. Often one needs to extract a handful of specific pages from a huge document, and the whole errand can feel very laborious. This is exactly why we will be devoting this tutorial to show you the best methods and the finest tools you need to extract pages from PDF files in Linux.

Using an online tool

PDF files have become one of the most common means of documenting and distributing data. Owing to their popularity, many websites and programs are designed particularly to manipulate these files. Speaking of which, ILovePDF is a website devoted entirely to this purpose. It has many tools that you can use for free to split, merge, convert, organize, protect, and compress PDF files.

Since we want to extract pages from PDF files, we will use the PDF Splitter tool offered by the website as mentioned above. Once you have the PDF document you want to extract pages from, click here to visit the online PDF Splitter tool.

Click the Select PDF file button and navigate to your document. Once you have uploaded it, you can select whether you want to extract pages or split the file by range.

Go ahead and select the options you need from the buttons on the right side. Once you are done, click the Split PDF, and that should be it. It will initialize downloading a .zip file that contains your extracted pages.

ILovePDF also has a free downloadable app, but unfortunately, it is only available for Windows and macOS. However, that does not take away from its ability to help you extract pages from PDFs on Linux since you can use it online too. With that being said, you can now use a completely free online PDF splitting tool to select specific pages from PDF files and extract them without any trouble!

Using PDFShuffler

If for whatever reason – may it be due to privacy concerns or lack of functionality – the previous method did not convince you, fret not, as we have more favorable recommendations for you to try out.

One of which is PDFShuffler, a handy python-gtk app that lets its users manipulate PDF files easily. Its features include merging, splitting, cropping, rotating, and rearranging PDF files. The tool adds to its extensive functionality through its easy-to-grasp and intuitive graphical interface.

Читайте также:  Запуск графической оболочки альт линукс

You can click here to download PDFShuffler from Source Forge, or you can do it the old-fashioned way through the command line. Navigate to the Activities menu or press Ctrl + Alt + T on your keyboard to open a new Terminal window.

Having done that, run the commands below to the first check for updates and then install PDFShuffler on your Linux system. (These commands are for Ubuntu 20.04, but other versions should not be too different from these).

Once the installation is complete, find the newly installed software in the Activities menu and run it. The default screen should look something like the image below.

The next step is to input your PDF file into the program by clicking the File button and selecting the Add option from the drop-down menu.

Once done, configure your extraction settings and split the file. The output should give you the desired extracted pages from the input document.

Using PDFtk

If you have a special appreciation for command-line programs rather than ones with graphical interfaces, then PDFtk is the way to go. It is an efficient CLI solution for users that need to extract specific pages from PDF files. Let us look at how you can install it on various Linux distributions and how to use it.

Go back to your Terminal window or open a new one and run the following commands if you use Ubuntu or Debian.

However, if you do not have the universe repository enabled, the command mentioned above will not work. You can enable this repository by running the command below.

Having done that, go back to the first command to install PDFtk.

If you are using Arch Linux or one of its variants, run the command below. (PDFtk is easily accessible through the community repository).

Similarly, if you are on openSUSE, run the command below to install PDFtk.

Lastly, if you have snap enabled, you can get this tool through a snap command as well.

Next, let us take a look at the usage of PDFtk. As we mentioned earlier, this is a CLI tool, so all you need to do is run a small command to get what you need.

Now, what is going on in this command? First, input.pdf is the document that needs to be split. The 3-4 parameter specifies page number range, 3 to 4. Next, we have the output filename, which is output_p3-4.pdf. Simple enough, and you should get the hang of it in no time.

However, you may not be looking to split a PDF file by a page number range; rather, extracting a bunch of particular pages into separate PDF files. Worry not, as you can do that through this tool as well. All you need to do is make a slight change in the command we mentioned earlier. This change is shown below.

With that done, you can split pages 3 and 4 and save them as output.pdf.

Conclusion

In this guide, we went into great depth about how you can extract pages from PDF files. We looked at a handy online tool, then a downloadable GUI-based program, and lastly, a command-line solution. The tools mentioned above are rich in terms of features and ought to get the job done easily.

About the author

Zeeman Memon

Hi there! I’m a Software Engineer who loves to write about tech. You can reach out to me on LinkedIn.

Источник

Оцените статью
Adblock
detector