Tell me more ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've got a PDF of a scanned document that's around 20MB and I need to drastically reduce the filesize to be able to email it. I've tried

gs -sDevice=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

but output.pdf isn't created. Instead, I get an X Viewer for Ghostscript briefly. Where am I going wrong?

share|improve this question
Please see this related Q&A for a number of GUI front ends to ghostscript that should make the process of reducing PDF filesizes easier. – Glutanimate Apr 11 at 21:58

3 Answers

up vote 11 down vote accepted

Here is a script for rewriting scanned pdfs:

#!/bin/sh

gs  -q -dNOPAUSE -dBATCH -dSAFER \
    -sDEVICE=pdfwrite \
    -dCompatibilityLevel=1.3 \
    -dPDFSETTINGS=/screen \
    -dEmbedAllFonts=true \
    -dSubsetFonts=true \
    -dColorImageDownsampleType=/Bicubic \
    -dColorImageResolution=72 \
    -dGrayImageDownsampleType=/Bicubic \
    -dGrayImageResolution=72 \
    -dMonoImageDownsampleType=/Bicubic \
    -dMonoImageResolution=72 \
    -sOutputFile=out.pdf \
     $1

You could customise it a bit to make it more reusable but if you only have one pdf, you could just replace $1 with your pdf filename and bung it in a terminal.

share|improve this answer
Works a treat, thanks Oli. You've answered pretty much everything I've asked on here so far :-D – Rob Cowell Sep 1 '10 at 8:15

I usually use ps2pdf to do this (easier syntax), something like this:

ps2pdf -dPDFSETTINGS=/ebook BiggerPdf SmallerPDF

I use the following python script to reduce the size of all the pdf files in a dir in a production server (8.04). So it should work.

#!/usr/bin/python

import os

for fich in os.listdir('.'):
        if fich[-3:]=="pdf":
                os.system("ps2pdf -dPDFSETTINGS=/ebook %s reduc/%s" % (fich,fich))
share|improve this answer
Thanks for the alternative solution. I tried Oli's first and it gave me the result I needed, but I will keep this one for future reference too. – Rob Cowell Sep 1 '10 at 8:17

If converting to djvu would also be ok and if no colors are involved, you could try the following:

Convert the pdf to jpg files using pdfimages -j

If you get pbm files instead, you should do the intermediate step:

for FILENAME in $(ls *.pbm); do convert $FILENAME ${FILENAME%.*}.jpg ;done

The convert command is from the imagemagick package.

Then use scantailor to make tif's out of it.

In a last step you go to scantailors out direcory (where the tif's are located) and apply djvubind to that directory.

This should reduce the filesize drastically without big quality loss of the text. If you want finer control over the ocr-backend, you may try djvubind --no-ocr and use ocrodjvu to add the ocr layer afterwards.

If you have color's in your document things get a bit more complicated. Instead of djvubind you could use didjvu and in scantailor you have to change to mixed mode and select sometimes color-images manually.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.