Resize.sh: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "==Script== <syntaxhighlight lang="bash"> #! /bin/bash pdffile=$1; dpi=$2 gs \ -o "${pdffile%.pdf}-resized.pdf" \ -sDEVICE=pdfwrite \ -dDownsampleColorImages=true \ -dDownsampleGrayImages=true \ -dDownsampleMonoImages=true \ -dColorImageResolution=$dpi \ -dGrayImageResolution=$dpi \ -dMonoImageResolution=$dpi \ -dColorImageDownsampleThreshold=1.0 \ -dGrayImageDownsampleThreshold=1.0 \ -dMonoImageDownsampleThreshold=1.0 \ "${pdffile}" </syntaxh...")
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
==Script==
This is a bash script based on Ghostscript that can be used to compress/resize a PDF.
 
This is a version of a script called <code>resample.sh</code> written by [http://osp.kitchen OSP].
 
===Script===


<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
Line 22: Line 26:
</syntaxhighlight>
</syntaxhighlight>


==How to use it?==
===How to use it?===


Save the code above to a file called <code>resize.sh</code>.
Save the code above to a file called <code>resize.sh</code>.
Line 32: Line 36:
For example:
For example:


  $ ./compresspdf.sh myfile.pdf 300
  $ ./resize.sh myfile.pdf 300


The output will be something like:
The output will be something like:


<code>myfile-resized.pdf</code>
<code>myfile-resized.pdf</code>
[[Category:Cookbook]]
[[Category:PagedMedia]]
[[Category:Boilerplates]]

Latest revision as of 11:47, 3 January 2025

This is a bash script based on Ghostscript that can be used to compress/resize a PDF.

This is a version of a script called resample.sh written by OSP.

Script

#! /bin/bash

pdffile=$1;
dpi=$2 

gs \
  -o "${pdffile%.pdf}-resized.pdf" \
  -sDEVICE=pdfwrite \
  -dDownsampleColorImages=true \
  -dDownsampleGrayImages=true \
  -dDownsampleMonoImages=true \
  -dColorImageResolution=$dpi \
  -dGrayImageResolution=$dpi \
  -dMonoImageResolution=$dpi \
  -dColorImageDownsampleThreshold=1.0 \
  -dGrayImageDownsampleThreshold=1.0 \
  -dMonoImageDownsampleThreshold=1.0 \
   "${pdffile}"

How to use it?

Save the code above to a file called resize.sh.

The script requires two arguments:

$ ./resize.sh <file.pdf> <resolution in DPI>

For example:

$ ./resize.sh myfile.pdf 300

The output will be something like:

myfile-resized.pdf