share
Unix & LinuxHow to remove pages from a PDF while leaving the document otherwise unchanged
[+5] [1] pez
[2020-04-15 19:14:03]
[ pdf pdftk ]
[ https://unix.stackexchange.com/questions/580305/how-to-remove-pages-from-a-pdf-while-leaving-the-document-otherwise-unchanged ]

I have a PDF book that I want to remove a few pages from to reduce the file size. My normal solution to this didn't work, and when I tried others they introduced new problems:

As you can see, it's surprisingly tricky to remove pages while otherwise leaving the document the same. Any advice on other solutions, or figuring out what's going on with these, would be much apreciated!

Have you tried community.coherentpdf.com? - Arkadiusz Drabczyk
Hadn't heard of it! I downloaded it but couldn't figure out how to install it. I found the cpdf executable for Linux x64, but when I run it from the terminal I just get a license warning. - pez
Type --help or see the examples on the website: cpdf in.pdf 1-3,12-end -o out.pdf - Arkadiusz Drabczyk
I can't get the cpdf command to be recognized by the terminal. - pez
You have said that you can run it in your previous post. It's not the terminal that recognizes the commands. To run pdf cd to Linux-Intel-64bit or Linux-Intel-32bit and run it ./cpdf - Arkadiusz Drabczyk
I said I found the executable. When I try to run it like you suggest I only get the following: For non-commercial use only To purchase a license visit coherentpdf.com - pez
Re-read my comment unix.stackexchange.com/questions/580305/… - Arkadiusz Drabczyk
That's not helpful. The command doesn't work, I can't install it to make it work and I can't find any relevant help file. - pez
You don't need to install it. Invoke help with ./cpdf --help. And, as I already said, look into examples posted on the website. - Arkadiusz Drabczyk
[+3] [2022-05-23 02:52:34] Olivier

It is quite strange that pdftk yields a bigger document in your case. Have you tried the exact following command, taken from here [1]?

pdftk infile.pdf cat 1-r2 output outfile.pdf

(please note that you can change the page selection, following your needs, by specifying multiple ranges as stated in a comment from the link I point to)

If, for some reason, there is no way to avoid pdftk yielding bigger files, you might want to try pdfjam, following that example:

pdfjam infile.pdf <page ranges> --landscape -o outfile.pdf

But bare in mind that pdfjam might want to add extra margins in order to fit a printed page format, unlike pdftk.

[1] https://stackoverflow.com/a/17713684/7009806

1