Compresspdf.sh: Difference between revisions

From creative crowd wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 32: Line 32:


'''In which context was it made?'''<br>  
'''In which context was it made?'''<br>  
The script is written by [http://osp.kitchen Open Source Publishing]. It has since travelled through other practices to be used for a variety of applications, usually at the eleventh hour before sending PDFs to print and for grant applications.
The script is written by [http://osp.kitchen Open Source Publishing]. It has since travelled through other practices to be used for a variety of applications, usually at the eleventh hour before sending PDFs via email and webforms.


'''What software does it use?'''<br>
'''What software does it use?'''<br>
Line 41: Line 41:


'''On which systems can this script run?'''<br>
'''On which systems can this script run?'''<br>
This works on Linux systems, also on Mac OS. Windows works differently, and it is likely it won't work there.
This works from the command line in terminal sessions on Linux systems, also on Mac OS. Windows has a different shell, and it is likely it won't work there.


'''How to run the script?'''<br>
'''How to run the script?'''<br>
Line 60: Line 60:
<code>input-resampled.pdf</code>
<code>input-resampled.pdf</code>


==Compressing the PDF for the newspaper ''Toward A Minor Tech''==
==Making a portfolio PDF at 23:59==


This script has been used many times on many machines. It's super handy when making files that need to be sent over a network. One particular use was when making the final final final PDF to be sent to the printer for the newspaper ''Toward A Minor Tech'' in January 2023 at Varia.
This script has been used many times on many machines. It's super handy when making files that need to be sent over a network. One particular use was when making a final final final portfolio PDF for a grant application at the eleventh hour.


The newspaper was created during a book sprint, where writers and editors worked in London, while the designers worked in Rotterdam. High-resolution images were uploaded to this very wiki so that they would appear crisp and non-pixelated in the printed newspaper.
Usually, the portfolio is the last thing I make. I don't have a template to work from. I should be better organised! And images are added willy-nilly, tailored to the particular grant application. And using CSS-to-print to make a PDF means that your software doesn't have a handy option to compress files when exporting, as when using Adobe InDesign and other proprietory software.


BUT! At the eleventh hour, we found the PDF to be quite large. We needed to send this on to the printer [https://www.tripiti.nl/ Drukkerij Tripiti] in Rotterdam, and email was our preferred option. Of course, a USB flash drive could be hand-delivered, but this was not the fastest way. Also it would be a bit weird, in 2023 who delivers files by hand? And there is no signage on the door at Drukkerij Tripiti, nor indication of what their business hours are.
So literally at the eleventh hour, the resulting PDF was quite large (128mb!). I needed to send this through a webform, and the specifications were that it  could not be bigger than 10mb.


So, we used this script. We managed to get the file down to a manageable size without stress.
So, I used this script at 23:58. I managed to get the file down to a manageable size without stress, and pressed send in time. In the end I did not get the grant, but I got the script :)


[[Category:Documentation]]
[[Category:Documentation]]

Revision as of 07:53, 7 April 2023

Script

A PDF's size before compression
The resampled PDF's size, after compression
#! /bin/bash

pdffile=$1;
dpi=$2 

gs \
  -o "${pdffile%.pdf}-resampled.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 work with it?

What does this script do?
This script squashes large PDFs into very small ones.

In which context was it made?
The script is written by Open Source Publishing. It has since travelled through other practices to be used for a variety of applications, usually at the eleventh hour before sending PDFs via email and webforms.

What software does it use?
ghostscript

How to download these pieces of software?
Go to the URL https://www.ghostscript.com/, you can download it from there.

On which systems can this script run?
This works from the command line in terminal sessions on Linux systems, also on Mac OS. Windows has a different shell, and it is likely it won't work there.

How to run the script?
After installing the software ghostscript (see above), save the code above as a bash script with the .sh extension, for example: compresspdf.sh. Don't forget to add #! /bin/bash to the top of your script!

Then, in a terminal session, navigate to the directory where you have the file saved. You should add the PDF you want to compress to the same directory.

Then do:

./compresspdf.sh <file.pdf> <resolution in DPI>

For example:

./compresspdf.sh input.pdf 300

The output will be something like:

input-resampled.pdf

Making a portfolio PDF at 23:59

This script has been used many times on many machines. It's super handy when making files that need to be sent over a network. One particular use was when making a final final final portfolio PDF for a grant application at the eleventh hour.

Usually, the portfolio is the last thing I make. I don't have a template to work from. I should be better organised! And images are added willy-nilly, tailored to the particular grant application. And using CSS-to-print to make a PDF means that your software doesn't have a handy option to compress files when exporting, as when using Adobe InDesign and other proprietory software.

So literally at the eleventh hour, the resulting PDF was quite large (128mb!). I needed to send this through a webform, and the specifications were that it could not be bigger than 10mb.

So, I used this script at 23:58. I managed to get the file down to a manageable size without stress, and pressed send in time. In the end I did not get the grant, but I got the script :)