Command line tool to crop PDF files
I am looking for an open source command line tool to crop PDF file just like we can do in Adobe Acrobat Pro. I have tried PdfTk, ImageMagick, PyPDF, and GhostScript—all with no success so far.
command-line pdf open-source
add a comment |
I am looking for an open source command line tool to crop PDF file just like we can do in Adobe Acrobat Pro. I have tried PdfTk, ImageMagick, PyPDF, and GhostScript—all with no success so far.
command-line pdf open-source
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for.
– xubuntix
Apr 24 '12 at 8:50
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop
– Rakesh
Apr 24 '12 at 8:56
add a comment |
I am looking for an open source command line tool to crop PDF file just like we can do in Adobe Acrobat Pro. I have tried PdfTk, ImageMagick, PyPDF, and GhostScript—all with no success so far.
command-line pdf open-source
I am looking for an open source command line tool to crop PDF file just like we can do in Adobe Acrobat Pro. I have tried PdfTk, ImageMagick, PyPDF, and GhostScript—all with no success so far.
command-line pdf open-source
command-line pdf open-source
edited May 18 '12 at 23:35
Kazark
553425
553425
asked Apr 24 '12 at 8:47
RakeshRakesh
6031810
6031810
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for.
– xubuntix
Apr 24 '12 at 8:50
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop
– Rakesh
Apr 24 '12 at 8:56
add a comment |
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for.
– xubuntix
Apr 24 '12 at 8:50
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop
– Rakesh
Apr 24 '12 at 8:56
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for.
– xubuntix
Apr 24 '12 at 8:50
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for.
– xubuntix
Apr 24 '12 at 8:50
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop
– Rakesh
Apr 24 '12 at 8:56
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop
– Rakesh
Apr 24 '12 at 8:56
add a comment |
8 Answers
8
active
oldest
votes
I would suggest you take a look at PDFcrop.
If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run
pdfcrop --margins '5 10 20 30' input.pdf output.pdf
in terminal. To actually crop something away, use negative values in the argument for crop. For example,
pdfcrop --margins '-50 -50 -50 -50' input.pdf output.pdf
crops 50 pts from the left, top, right, bottom (in this order).
If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.
Cropping multiple files
Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.
Create a new empty file, and call it something.sh. Open it with a text editor and insert the following:
#!/bin/bash
for FILE in ./*.pdf; do
pdfcrop "${FILE}"
done
Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after pdfcrop.
Note that instead of specifying negative margins, one can also use--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.
– bluenote10
Mar 3 '15 at 16:22
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
I fear it's all or nothing.pdfcrop --helplists the available options. I cannot see anything there that would allow specifying a range of pages.
– Rasmus
Mar 13 '17 at 15:20
5
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
|
show 3 more comments
Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:
sudo apt-get install texlive-extra-utils
Then crop pdf files using pdf crop command as:
pdfcrop input.pdf output.pdf
use --help to see more amazing parameters like --margins
pdfcrop --margins 5 input.pdf output.pdf
which crop pdf with 5 bp from each side of page
The measurement isbp, which is slightly different frompt. See tex.stackexchange.com/questions/8260/….
– koppor
Sep 2 '17 at 16:06
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
1
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to dogs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdfafterwards, which fixed the file size.
– fiktor
Feb 24 '18 at 19:07
add a comment |
You can also crop PDF files simply using Ghostscript. I have written a small script to simplify the process (inspired by this answer):
#!/bin/bash
if [ $# -lt 5 ]
then
echo "Usage: `basename $0` <pdf-file> <x_min> <x_max> <y_min> <y_max>"
echo "Notes:"
echo " - all coordinates are absolute; no calculation of width/height necessary"
echo " - use 'gv' to determine the coordinates"
exit 65
fi
file="$1"
xmin="$2"
xmax="$3"
ymin="$4"
ymax="$5"
base="${file%.*}"
outfile="${base}_cropped.pdf"
echo "writing to: $outfile"
gs
-o $outfile
-sDEVICE=pdfwrite
-c "[/CropBox [$xmin $ymin $xmax $ymax] /PAGES pdfmark"
-f $file
In order to determine the coordinates for cropping, I use gv, which prints the coordinates of the mouse cursor using the same units as Ghostscript. For example, here I determine the minimum coordinates for x/y (the values in the upper left corner):

Now the maximum coordinates:

And finally, I run the script pdf_crop_by_coordinates.sh test.pdf 45 429 38 419 producing a test_cropped.pdf which looks like that:

I have no idea though, how the Ghostscript solution compares to pdfcrop in terms of quality and correctness.
add a comment |
When I can't do something with pdftk, the next place I turn is PDFjam, which is a command-line wrapper for the pdfpages LaTeX package (hence you also need that and a TeX distro installed). For help on how to use it, I recommend the regular help screen:
pdfjam --help
as the man page is sparse and the Web page concentrates on examples.
To crop a PDF, the command you need is something like this:
pdfjam --keepinfo --trim "10mm 15mm 10mm 15mm" --clip true --suffix "cropped" input.pdf
This will output a file called input-cropped.pdf. The order of the trims should be left, bottom, right, top, as per includegraphics from graphicx.
To give an idea of how it compares with PDFcrop, I had cause to crop a quite fancy PDF recently. My original was 675 kB, my cropped version via PDFjam was 1.2 MB, while a version cropped via PDFcrop was 4.5 MB. While both PDFjam and PDFcrop stripped out the embedded hyperlinks and bookmarks, PDFjam with the --keepinfo option preserved the document properties (e.g. title, author, subject).
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
add a comment |
If a graphical tool is also fine I would recommend krop: http://arminstraub.com/software/krop
add a comment |
This may help you.
This is in accordance with the newer version of Ubuntu and life.
This is Master PDF Editor. You can use it crop, add some stuff, etc.
Example:
This is before

This is after ctrl + k

add a comment |
You could use a pypdf script from this page. But in the answer to this stackexchange question, there seem to be many options as well.
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
add a comment |
Briss is not command line, but worth a look at.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f124692%2fcommand-line-tool-to-crop-pdf-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
I would suggest you take a look at PDFcrop.
If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run
pdfcrop --margins '5 10 20 30' input.pdf output.pdf
in terminal. To actually crop something away, use negative values in the argument for crop. For example,
pdfcrop --margins '-50 -50 -50 -50' input.pdf output.pdf
crops 50 pts from the left, top, right, bottom (in this order).
If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.
Cropping multiple files
Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.
Create a new empty file, and call it something.sh. Open it with a text editor and insert the following:
#!/bin/bash
for FILE in ./*.pdf; do
pdfcrop "${FILE}"
done
Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after pdfcrop.
Note that instead of specifying negative margins, one can also use--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.
– bluenote10
Mar 3 '15 at 16:22
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
I fear it's all or nothing.pdfcrop --helplists the available options. I cannot see anything there that would allow specifying a range of pages.
– Rasmus
Mar 13 '17 at 15:20
5
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
|
show 3 more comments
I would suggest you take a look at PDFcrop.
If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run
pdfcrop --margins '5 10 20 30' input.pdf output.pdf
in terminal. To actually crop something away, use negative values in the argument for crop. For example,
pdfcrop --margins '-50 -50 -50 -50' input.pdf output.pdf
crops 50 pts from the left, top, right, bottom (in this order).
If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.
Cropping multiple files
Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.
Create a new empty file, and call it something.sh. Open it with a text editor and insert the following:
#!/bin/bash
for FILE in ./*.pdf; do
pdfcrop "${FILE}"
done
Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after pdfcrop.
Note that instead of specifying negative margins, one can also use--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.
– bluenote10
Mar 3 '15 at 16:22
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
I fear it's all or nothing.pdfcrop --helplists the available options. I cannot see anything there that would allow specifying a range of pages.
– Rasmus
Mar 13 '17 at 15:20
5
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
|
show 3 more comments
I would suggest you take a look at PDFcrop.
If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run
pdfcrop --margins '5 10 20 30' input.pdf output.pdf
in terminal. To actually crop something away, use negative values in the argument for crop. For example,
pdfcrop --margins '-50 -50 -50 -50' input.pdf output.pdf
crops 50 pts from the left, top, right, bottom (in this order).
If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.
Cropping multiple files
Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.
Create a new empty file, and call it something.sh. Open it with a text editor and insert the following:
#!/bin/bash
for FILE in ./*.pdf; do
pdfcrop "${FILE}"
done
Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after pdfcrop.
I would suggest you take a look at PDFcrop.
If you wish to crop a pdf with left, top, right and bottom margins of 5, 10, 20, and 30 pt (points), then run
pdfcrop --margins '5 10 20 30' input.pdf output.pdf
in terminal. To actually crop something away, use negative values in the argument for crop. For example,
pdfcrop --margins '-50 -50 -50 -50' input.pdf output.pdf
crops 50 pts from the left, top, right, bottom (in this order).
If you run only the command pdfcrop input, it will output a file titled input-crop.pdf with zero margins. I find this very handy when including pdf illustrations in documents.
Cropping multiple files
Unfortunately, pdfcrop cannot crop multiple files at the time. It is however easy to write a script that will crop all pdfs in the folder the script is located in.
Create a new empty file, and call it something.sh. Open it with a text editor and insert the following:
#!/bin/bash
for FILE in ./*.pdf; do
pdfcrop "${FILE}"
done
Save it, and close. Then right click the file, go to Properties > Permissions and check the field Allow executing file as program. Now close the dialog. Run the script by double clicking it and choosing Run in Terminal. And new, zero-margin cropped version of all pdfs with suffix -crop will now be printed in the folder. If you want margins or other things, you can of course just open the script and add arguments after pdfcrop.
edited Feb 9 '18 at 12:26
dessert
22.4k56198
22.4k56198
answered Aug 23 '12 at 13:43
RasmusRasmus
3,62482852
3,62482852
Note that instead of specifying negative margins, one can also use--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.
– bluenote10
Mar 3 '15 at 16:22
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
I fear it's all or nothing.pdfcrop --helplists the available options. I cannot see anything there that would allow specifying a range of pages.
– Rasmus
Mar 13 '17 at 15:20
5
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
|
show 3 more comments
Note that instead of specifying negative margins, one can also use--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.
– bluenote10
Mar 3 '15 at 16:22
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
I fear it's all or nothing.pdfcrop --helplists the available options. I cannot see anything there that would allow specifying a range of pages.
– Rasmus
Mar 13 '17 at 15:20
5
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
Note that instead of specifying negative margins, one can also use
--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.– bluenote10
Mar 3 '15 at 16:22
Note that instead of specifying negative margins, one can also use
--bbox "<left> <bottom> <right> <top>". This allows to use the approach to determine the crop area described in my answer below.– bluenote10
Mar 3 '15 at 16:22
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
Is there a possibility of telling page number(which need to be cropped)?
– L.K.
Mar 13 '17 at 12:04
I fear it's all or nothing.
pdfcrop --help lists the available options. I cannot see anything there that would allow specifying a range of pages.– Rasmus
Mar 13 '17 at 15:20
I fear it's all or nothing.
pdfcrop --help lists the available options. I cannot see anything there that would allow specifying a range of pages.– Rasmus
Mar 13 '17 at 15:20
5
5
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Comparing the size of PDFCrop's output to its input, it looks as if pdfcrop only modifies the bounding boxes. It doesn't remove data. So this approach would be unsuitable to make the pdf smaller, or hide information.
– init_js
Apr 27 '17 at 21:10
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
Like a charm! even with the margins the pdf needed!
– jojo
Jul 8 '17 at 13:33
|
show 3 more comments
Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:
sudo apt-get install texlive-extra-utils
Then crop pdf files using pdf crop command as:
pdfcrop input.pdf output.pdf
use --help to see more amazing parameters like --margins
pdfcrop --margins 5 input.pdf output.pdf
which crop pdf with 5 bp from each side of page
The measurement isbp, which is slightly different frompt. See tex.stackexchange.com/questions/8260/….
– koppor
Sep 2 '17 at 16:06
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
1
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to dogs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdfafterwards, which fixed the file size.
– fiktor
Feb 24 '18 at 19:07
add a comment |
Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:
sudo apt-get install texlive-extra-utils
Then crop pdf files using pdf crop command as:
pdfcrop input.pdf output.pdf
use --help to see more amazing parameters like --margins
pdfcrop --margins 5 input.pdf output.pdf
which crop pdf with 5 bp from each side of page
The measurement isbp, which is slightly different frompt. See tex.stackexchange.com/questions/8260/….
– koppor
Sep 2 '17 at 16:06
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
1
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to dogs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdfafterwards, which fixed the file size.
– fiktor
Feb 24 '18 at 19:07
add a comment |
Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:
sudo apt-get install texlive-extra-utils
Then crop pdf files using pdf crop command as:
pdfcrop input.pdf output.pdf
use --help to see more amazing parameters like --margins
pdfcrop --margins 5 input.pdf output.pdf
which crop pdf with 5 bp from each side of page
Thanks for Rasmus, you can install pdfcrop from texlive-extra-utils package:
sudo apt-get install texlive-extra-utils
Then crop pdf files using pdf crop command as:
pdfcrop input.pdf output.pdf
use --help to see more amazing parameters like --margins
pdfcrop --margins 5 input.pdf output.pdf
which crop pdf with 5 bp from each side of page
edited Sep 3 '17 at 13:21
answered Apr 13 '14 at 12:22
sarigalinsarigalin
40144
40144
The measurement isbp, which is slightly different frompt. See tex.stackexchange.com/questions/8260/….
– koppor
Sep 2 '17 at 16:06
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
1
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to dogs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdfafterwards, which fixed the file size.
– fiktor
Feb 24 '18 at 19:07
add a comment |
The measurement isbp, which is slightly different frompt. See tex.stackexchange.com/questions/8260/….
– koppor
Sep 2 '17 at 16:06
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
1
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to dogs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdfafterwards, which fixed the file size.
– fiktor
Feb 24 '18 at 19:07
The measurement is
bp, which is slightly different from pt. See tex.stackexchange.com/questions/8260/….– koppor
Sep 2 '17 at 16:06
The measurement is
bp, which is slightly different from pt. See tex.stackexchange.com/questions/8260/….– koppor
Sep 2 '17 at 16:06
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
@koppor thanks, I edited my answer.
– sarigalin
Nov 1 '17 at 19:25
1
1
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to do
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdf afterwards, which fixed the file size.– fiktor
Feb 24 '18 at 19:07
For me pdfcrop inflated the file size from 300x (from 7MB to 2GB). I had to do
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS="/ebook" -sOutputFile=output2.pdf output.pdf afterwards, which fixed the file size.– fiktor
Feb 24 '18 at 19:07
add a comment |
You can also crop PDF files simply using Ghostscript. I have written a small script to simplify the process (inspired by this answer):
#!/bin/bash
if [ $# -lt 5 ]
then
echo "Usage: `basename $0` <pdf-file> <x_min> <x_max> <y_min> <y_max>"
echo "Notes:"
echo " - all coordinates are absolute; no calculation of width/height necessary"
echo " - use 'gv' to determine the coordinates"
exit 65
fi
file="$1"
xmin="$2"
xmax="$3"
ymin="$4"
ymax="$5"
base="${file%.*}"
outfile="${base}_cropped.pdf"
echo "writing to: $outfile"
gs
-o $outfile
-sDEVICE=pdfwrite
-c "[/CropBox [$xmin $ymin $xmax $ymax] /PAGES pdfmark"
-f $file
In order to determine the coordinates for cropping, I use gv, which prints the coordinates of the mouse cursor using the same units as Ghostscript. For example, here I determine the minimum coordinates for x/y (the values in the upper left corner):

Now the maximum coordinates:

And finally, I run the script pdf_crop_by_coordinates.sh test.pdf 45 429 38 419 producing a test_cropped.pdf which looks like that:

I have no idea though, how the Ghostscript solution compares to pdfcrop in terms of quality and correctness.
add a comment |
You can also crop PDF files simply using Ghostscript. I have written a small script to simplify the process (inspired by this answer):
#!/bin/bash
if [ $# -lt 5 ]
then
echo "Usage: `basename $0` <pdf-file> <x_min> <x_max> <y_min> <y_max>"
echo "Notes:"
echo " - all coordinates are absolute; no calculation of width/height necessary"
echo " - use 'gv' to determine the coordinates"
exit 65
fi
file="$1"
xmin="$2"
xmax="$3"
ymin="$4"
ymax="$5"
base="${file%.*}"
outfile="${base}_cropped.pdf"
echo "writing to: $outfile"
gs
-o $outfile
-sDEVICE=pdfwrite
-c "[/CropBox [$xmin $ymin $xmax $ymax] /PAGES pdfmark"
-f $file
In order to determine the coordinates for cropping, I use gv, which prints the coordinates of the mouse cursor using the same units as Ghostscript. For example, here I determine the minimum coordinates for x/y (the values in the upper left corner):

Now the maximum coordinates:

And finally, I run the script pdf_crop_by_coordinates.sh test.pdf 45 429 38 419 producing a test_cropped.pdf which looks like that:

I have no idea though, how the Ghostscript solution compares to pdfcrop in terms of quality and correctness.
add a comment |
You can also crop PDF files simply using Ghostscript. I have written a small script to simplify the process (inspired by this answer):
#!/bin/bash
if [ $# -lt 5 ]
then
echo "Usage: `basename $0` <pdf-file> <x_min> <x_max> <y_min> <y_max>"
echo "Notes:"
echo " - all coordinates are absolute; no calculation of width/height necessary"
echo " - use 'gv' to determine the coordinates"
exit 65
fi
file="$1"
xmin="$2"
xmax="$3"
ymin="$4"
ymax="$5"
base="${file%.*}"
outfile="${base}_cropped.pdf"
echo "writing to: $outfile"
gs
-o $outfile
-sDEVICE=pdfwrite
-c "[/CropBox [$xmin $ymin $xmax $ymax] /PAGES pdfmark"
-f $file
In order to determine the coordinates for cropping, I use gv, which prints the coordinates of the mouse cursor using the same units as Ghostscript. For example, here I determine the minimum coordinates for x/y (the values in the upper left corner):

Now the maximum coordinates:

And finally, I run the script pdf_crop_by_coordinates.sh test.pdf 45 429 38 419 producing a test_cropped.pdf which looks like that:

I have no idea though, how the Ghostscript solution compares to pdfcrop in terms of quality and correctness.
You can also crop PDF files simply using Ghostscript. I have written a small script to simplify the process (inspired by this answer):
#!/bin/bash
if [ $# -lt 5 ]
then
echo "Usage: `basename $0` <pdf-file> <x_min> <x_max> <y_min> <y_max>"
echo "Notes:"
echo " - all coordinates are absolute; no calculation of width/height necessary"
echo " - use 'gv' to determine the coordinates"
exit 65
fi
file="$1"
xmin="$2"
xmax="$3"
ymin="$4"
ymax="$5"
base="${file%.*}"
outfile="${base}_cropped.pdf"
echo "writing to: $outfile"
gs
-o $outfile
-sDEVICE=pdfwrite
-c "[/CropBox [$xmin $ymin $xmax $ymax] /PAGES pdfmark"
-f $file
In order to determine the coordinates for cropping, I use gv, which prints the coordinates of the mouse cursor using the same units as Ghostscript. For example, here I determine the minimum coordinates for x/y (the values in the upper left corner):

Now the maximum coordinates:

And finally, I run the script pdf_crop_by_coordinates.sh test.pdf 45 429 38 419 producing a test_cropped.pdf which looks like that:

I have no idea though, how the Ghostscript solution compares to pdfcrop in terms of quality and correctness.
edited May 23 '17 at 12:39
Community♦
1
1
answered Mar 3 '15 at 12:38
bluenote10bluenote10
1,0081020
1,0081020
add a comment |
add a comment |
When I can't do something with pdftk, the next place I turn is PDFjam, which is a command-line wrapper for the pdfpages LaTeX package (hence you also need that and a TeX distro installed). For help on how to use it, I recommend the regular help screen:
pdfjam --help
as the man page is sparse and the Web page concentrates on examples.
To crop a PDF, the command you need is something like this:
pdfjam --keepinfo --trim "10mm 15mm 10mm 15mm" --clip true --suffix "cropped" input.pdf
This will output a file called input-cropped.pdf. The order of the trims should be left, bottom, right, top, as per includegraphics from graphicx.
To give an idea of how it compares with PDFcrop, I had cause to crop a quite fancy PDF recently. My original was 675 kB, my cropped version via PDFjam was 1.2 MB, while a version cropped via PDFcrop was 4.5 MB. While both PDFjam and PDFcrop stripped out the embedded hyperlinks and bookmarks, PDFjam with the --keepinfo option preserved the document properties (e.g. title, author, subject).
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
add a comment |
When I can't do something with pdftk, the next place I turn is PDFjam, which is a command-line wrapper for the pdfpages LaTeX package (hence you also need that and a TeX distro installed). For help on how to use it, I recommend the regular help screen:
pdfjam --help
as the man page is sparse and the Web page concentrates on examples.
To crop a PDF, the command you need is something like this:
pdfjam --keepinfo --trim "10mm 15mm 10mm 15mm" --clip true --suffix "cropped" input.pdf
This will output a file called input-cropped.pdf. The order of the trims should be left, bottom, right, top, as per includegraphics from graphicx.
To give an idea of how it compares with PDFcrop, I had cause to crop a quite fancy PDF recently. My original was 675 kB, my cropped version via PDFjam was 1.2 MB, while a version cropped via PDFcrop was 4.5 MB. While both PDFjam and PDFcrop stripped out the embedded hyperlinks and bookmarks, PDFjam with the --keepinfo option preserved the document properties (e.g. title, author, subject).
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
add a comment |
When I can't do something with pdftk, the next place I turn is PDFjam, which is a command-line wrapper for the pdfpages LaTeX package (hence you also need that and a TeX distro installed). For help on how to use it, I recommend the regular help screen:
pdfjam --help
as the man page is sparse and the Web page concentrates on examples.
To crop a PDF, the command you need is something like this:
pdfjam --keepinfo --trim "10mm 15mm 10mm 15mm" --clip true --suffix "cropped" input.pdf
This will output a file called input-cropped.pdf. The order of the trims should be left, bottom, right, top, as per includegraphics from graphicx.
To give an idea of how it compares with PDFcrop, I had cause to crop a quite fancy PDF recently. My original was 675 kB, my cropped version via PDFjam was 1.2 MB, while a version cropped via PDFcrop was 4.5 MB. While both PDFjam and PDFcrop stripped out the embedded hyperlinks and bookmarks, PDFjam with the --keepinfo option preserved the document properties (e.g. title, author, subject).
When I can't do something with pdftk, the next place I turn is PDFjam, which is a command-line wrapper for the pdfpages LaTeX package (hence you also need that and a TeX distro installed). For help on how to use it, I recommend the regular help screen:
pdfjam --help
as the man page is sparse and the Web page concentrates on examples.
To crop a PDF, the command you need is something like this:
pdfjam --keepinfo --trim "10mm 15mm 10mm 15mm" --clip true --suffix "cropped" input.pdf
This will output a file called input-cropped.pdf. The order of the trims should be left, bottom, right, top, as per includegraphics from graphicx.
To give an idea of how it compares with PDFcrop, I had cause to crop a quite fancy PDF recently. My original was 675 kB, my cropped version via PDFjam was 1.2 MB, while a version cropped via PDFcrop was 4.5 MB. While both PDFjam and PDFcrop stripped out the embedded hyperlinks and bookmarks, PDFjam with the --keepinfo option preserved the document properties (e.g. title, author, subject).
answered Jul 21 '15 at 15:29
Alex BallAlex Ball
30426
30426
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
add a comment |
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
Note: this does not really remove the content that becomes off-screen from the PDF, only hides it. Same as what @init_js comments on in the top-scored answer.
– Jan Żankowski
Jul 31 '18 at 16:25
add a comment |
If a graphical tool is also fine I would recommend krop: http://arminstraub.com/software/krop
add a comment |
If a graphical tool is also fine I would recommend krop: http://arminstraub.com/software/krop
add a comment |
If a graphical tool is also fine I would recommend krop: http://arminstraub.com/software/krop
If a graphical tool is also fine I would recommend krop: http://arminstraub.com/software/krop
answered May 18 '16 at 13:52
SundaySunday
5181411
5181411
add a comment |
add a comment |
This may help you.
This is in accordance with the newer version of Ubuntu and life.
This is Master PDF Editor. You can use it crop, add some stuff, etc.
Example:
This is before

This is after ctrl + k

add a comment |
This may help you.
This is in accordance with the newer version of Ubuntu and life.
This is Master PDF Editor. You can use it crop, add some stuff, etc.
Example:
This is before

This is after ctrl + k

add a comment |
This may help you.
This is in accordance with the newer version of Ubuntu and life.
This is Master PDF Editor. You can use it crop, add some stuff, etc.
Example:
This is before

This is after ctrl + k

This may help you.
This is in accordance with the newer version of Ubuntu and life.
This is Master PDF Editor. You can use it crop, add some stuff, etc.
Example:
This is before

This is after ctrl + k

answered Mar 14 '17 at 18:36
ShaminaShamina
23817
23817
add a comment |
add a comment |
You could use a pypdf script from this page. But in the answer to this stackexchange question, there seem to be many options as well.
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
add a comment |
You could use a pypdf script from this page. But in the answer to this stackexchange question, there seem to be many options as well.
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
add a comment |
You could use a pypdf script from this page. But in the answer to this stackexchange question, there seem to be many options as well.
You could use a pypdf script from this page. But in the answer to this stackexchange question, there seem to be many options as well.
edited May 23 '17 at 12:39
Community♦
1
1
answered Apr 24 '12 at 9:04
xubuntixxubuntix
4,7991839
4,7991839
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
add a comment |
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
I am not able to get what the left top right bottom parameters are. are they points, inches, centimeters ?
– Rakesh
Apr 24 '12 at 11:00
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
@Rakesh: See my answer for an explanation of the parameters and how to determine them easily.
– bluenote10
Mar 3 '15 at 13:12
add a comment |
Briss is not command line, but worth a look at.
add a comment |
Briss is not command line, but worth a look at.
add a comment |
Briss is not command line, but worth a look at.
Briss is not command line, but worth a look at.
answered Jan 13 at 15:01
weberjnweberjn
1214
1214
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f124692%2fcommand-line-tool-to-crop-pdf-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please describe what kind of cropping you can do with Adobe Acrobat pro? Because I do not have it and can therefore not tell what you are looking for.
– xubuntix
Apr 24 '12 at 8:50
In Adobe Acrobat Pro we can use the margin controls to crop the PDF. we can provide the value's for the top, bottom, right and left to crop
– Rakesh
Apr 24 '12 at 8:56