3

I have a PDF file (4.6MB) which was made by combining 6 different PDFs (containing both text and bitmap graphics) using pdftk in Ubuntu 12.04. I wish to compress this file to something close to 2MB without affecting its quality.

I have tried pdftk's "compress" option (couldn't compress it to 2 MB), also tried converting it to ps first and than back to pdf, it gives the following warning:

****Warning: considering '0000000000 XXXXX n' as a free entry.

and then hangs. qpdf also failed saying that the file is damaged.

Could someone help me out?

halfer
  • 19,824
  • 17
  • 99
  • 186
Harsh Purwar
  • 57
  • 1
  • 7
  • 1
    Are the graphics vector or bitmap? You might get some compression wins if you increase the bitmap lossiness - though I would imagine it would be better to do this at generation time, rather than reprocessing the file. – halfer Jun 15 '12 at 16:07
  • Ooh, [this](http://tex.stackexchange.com/questions/14429/pdftex-reduce-pdf-size-reduce-image-quality) looks like it will help. – halfer Jun 15 '12 at 16:09
  • I couldn't compress the graphics (it's bitmap by the way) in the pdf files since I do not have the source files for all the pdfs. – Harsh Purwar Jun 15 '12 at 16:54
  • 1
    Just a bit of advice for your next question. Give detail (e.g. that your graphics are bitmaps) and what you've tried (e.g. Multivalent). It'll save time for everyone! – halfer Jun 15 '12 at 20:04
  • Also: any luck with Ghostscript? – halfer Jun 15 '12 at 20:04
  • No with gs also I couldn't achieve such high compression ratio. I need to compress a file from 4.6 MB to about 2 MB. – Harsh Purwar Jun 16 '12 at 02:22
  • 2
    For those who might be looking for something like this: **Both the following answers are correct** – Harsh Purwar Feb 16 '13 at 17:27

3 Answers3

6

What result does Ghostscript give you? Try this command:

gs \
  -o output.pdf \
  -sDEVICE=pdfwrite \
  -dPDFSETTINGS=/screen \
   input.pdf
Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
  • No couldn't achieve required compression ratio. – Harsh Purwar Jun 16 '12 at 03:00
  • 1
    @Harsh Purwar: So how much **DID** this Ghostscript command reduce the file size?!? – Kurt Pfeifle Jun 16 '12 at 04:39
  • 1
    @Harsh Purwar: Without being able to have a look at + analyze the file in question, it is not possible to give better advice. It may simply be impossible to further reduce the file size. – Kurt Pfeifle Jun 16 '12 at 04:39
  • Well your gs command compressed it to about 4.0 MB. And yes now I also think that it might be impossible to compress it further without affecting the quality. Thanks any ways. – Harsh Purwar Jun 16 '12 at 07:26
  • 1
    @HarshPurwar - I recommend that you generally answer in more detail, and using answers such as this as _starting points_ for more research. So, does GS offer options to alter the compression ratio? Can you re-encode bitmaps with greater lossiness etc? Read the manual, rather than just saying that "it didn't work" `:)` – halfer Jun 16 '12 at 10:43
  • @halfer: Yes I shall keep that in mind and **no I can not re-encode the bitmaps** since I do not have the source files as well as the included graphics. _I will post a solution if I find it in the man page of GS._ Thanks. – Harsh Purwar Jun 16 '12 at 13:34
  • 1
    @HarshPurwar: gs can downsample included bitmaps when writing pdf. Check the manuals. – Martin Schröder Jun 16 '12 at 13:45
  • @HarshPurwar - I should have been more specific - when I said _re-encode the bitmaps_, I meant through GS, rather than re-creating the PDF from source, as per Martin's comment. – halfer Jun 16 '12 at 14:10
  • 1
    Right now it's 40 minutes before my PhD defense and my committee starts telling me they can't open the slides I sent them. This command saved everything. Thanks! – dranxo Oct 26 '12 at 19:48
  • @rcompton: I hope your PhD defense was not *as* 'tight' as your PDF slides were... :-) – Kurt Pfeifle Oct 30 '12 at 22:12
3

has this pdf file reserved infos? If it has no confidential data it would be interesting to see

anyway many times where qpdf fails, Multivalent works

you can try to use its Compress tool (it also attempts to repair pdf file)

Multivalent

java -cp path....to/Multivalent.jar tool.pdf.Compress file.pdf

Dingo
  • 2,619
  • 1
  • 22
  • 32
  • Tried using Multivalent but it couldn't compress my file to more than 4.1 MB. Though it suggests that: **additional compression may be possible with: -compact -jpeg -nopagepiece** And I have no idea how to implement it. I tried as follows but failed. _java -compact ./Multivalent.jar tool.pdf.Compress file.pdf_ – Harsh Purwar Jun 15 '12 at 16:50
  • right syntax is (assuming, for instance, you downloaded **Multivalent.jar** in /root: `java -cp /root/Multivalent.jar tool.pdf.Compress -jpeg -nopagepiece file.pdf` – Dingo Jun 15 '12 at 16:56
  • Ya now it works but still could achieve the required file size. Now it's compressed to 4.0 MB. Is there anything else I could try? – Harsh Purwar Jun 15 '12 at 17:03
  • 1
    beyond a certain limit, with pdf containing **raster images**, it is impossible to achieve an high compression ratio without sacrificing the quality. You must decide if you need quality or prefer degrade images for pdf intended **NOT FOR PRINT** but only to view on screen. A pdf with low-res images is useless, in my opinion, you need in any case an high quality backup copy to not lose ability to print file in good quality if necessary. if images inside pdf can tolerate **Black and White** binarization, I can modify answer to add instruction to use jbig2enc – Dingo Jun 15 '12 at 21:26
3

This works for me to repair the damaged PDF

sudo apt-get install mupdf-tools
mutool clean input.pdf output.pdf