3

I want to apply some improvements (change brightness, contrast, etc) to a pdf, to make it more readable, so I chose ImageMagick and pdftk. I used the following command to split the pdf into several single page pdf files, so I can operate with ImageMagick one file at a time.

pdftk a.pdf burst output %04d.pdf

At this time, everything is ok. I take one of these files (eg. 0038.pdf) to make my tests. For example, to adjust the contrast I used this command:

convert 0038.pdf -quality 100 -density 300 -brightness-contrast 0x10% out.pdf

But this is the result:

ORIGINAL

Original pdf

CONVERTED

Converted pdf

I tried to change the value of quality, density, size, resize, geometry and the output pdf has different size/resolution, but is always unreadable. So I realized that the problem is upstream of the conversion. It seems like the input pdf size and resolution are read wrongly from convert.

Infact, when I just type this command:

convert -verbose 0038.pdf out.pdf

I get:

/tmp/magick-9894W9c_JPl1I7QV1 PNG 380x482 380x482+0+0 8-bit sRGB 128KB 0.010u 0:00.010
0038.pdf PNG 380x482 380x482+0+0 16-bit sRGB 128KB 0.000u 0:00.000
0038.pdf=>out.pdf PNG 380x482 380x482+0+0 16-bit sRGB 125KB 0.050u 0:00.049
[ghostscript library] -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pngalpha" -dTextAlphaBits=4 -dGraphicsAlphaBits=4 "-r72x72"  "-sOutputFile=/tmp/magick-9894W9c_JPl1I7QV%d" "-f/tmp/magick-9894s1cR4gD9oYuz" "-f/tmp/magick-9894KMmuVq0n9U8c"

As you can see, the size is 380 x 482, but I know that the real size is 1653 x 2338 pixels.

This is the metadata of 0038.pdf (read with exiftool)

 ExifToolVersion = 9.70
  FileName = 0038.pdf
  Directory = .
  FileSize = 429577
  FileModifyDate = 1414935360
  FileAccessDate = 1414935693
  FileInodeChangeDate = 1414935693
  FilePermissions = 33188
  FileType = PDF
  MIMEType = application/pdf
  PDFVersion = 1.4
  Linearized = false
PDF dictionary (1 of 1) with 4 entries:
  0)  Info (SubDirectory) -->
  + [Info directory with 5 entries]
  | 0)  ModifyDate = (D:20141101192012Z)
  | 1)  CreateDate = (D:20141101192012Z)
  | 2)  Title = 0038
  | 3)  Creator = (pdftk 2.02 - www.pdftk.com)
  | 4)  Producer = (itext-paulo-155 \(itextpdf.sf.net-lowagie.com\))
  1)  ID = [<e5af52575d23dc1a2aca80f7453fa203>,<4cc6d7fb99aca8c755033ca2973b713c>]
  2)  Root (SubDirectory) -->
  + [Root directory with 3 entries]
  | 0)  Metadata (SubDirectory) -->
  | + [Metadata directory with 3 entries]
  | | 0)  Subtype = /XML
  | | 1)  Type = /Metadata
  | | 2)  Length = 3008
  | | + [XMP directory, 3008 bytes]
  | | | XMPToolkit = Image::ExifTool 9.70
  | | | Title = 0038
  | | | Artist = A
  | 1)  Type = /Catalog
  | 2)  Pages (SubDirectory) -->
  | + [Pages directory with 3 entries]
  | | 0)  Kids (SubDirectory) -->
  | | + [Kids directory with 7 entries]
  | | | 0)  Resources (SubDirectory) -->
  | | | + [Resources directory with 2 entries]
  | | | | 0)  ProcSet = [/PDF,/Text,/ImageB,/ImageC,/ImageI]
  | | | | 1)  XObject (SubDirectory) -->
  | | | | + [XObject directory with 1 entries]
  | | | | | 0)  JI19a (SubDirectory) -->
  | | | | | + [JI19a directory with 9 entries]
  | | | | | | 0)  Subtype = /Image
  | | | | | | 1)  Name = /JI19a
  | | | | | | 2)  Type = /XObject
  | | | | | | 3)  Width = 1653
  | | | | | | 4)  Filter = /DCTDecode
  | | | | | | 5)  Height = 2338
  | | | | | | 6)  BitsPerComponent = 8
  | | | | | | 7)  Length = 425229
  | | | | | | 8)  ColorSpace = /DeviceGray
  | | | 1)  Rotate = 90
  | | | 2)  Parent = ref(1 0 R)
  | | | 3)  Contents (SubDirectory) -->
  | | | + [Contents directory with 1 entries]
  | | | | 0)  Length = 57
  | | | 4)  Type = /Page
  | | | 5)  MediaBox = [22,440,504,820]
  | | | 6)  CropBox = [22,440,504,820]
  | | 1)  Type = /Pages
  | | 2)  PageCount = 1
  3)  Size = 10

Any ideas?

1
  • 1
    Can you add/attach example PDF file(s)?
    – ozbek
    Nov 7, 2014 at 1:26

1 Answer 1

6
+50

The problem arises, because ImageMagick cannot determine the resolution of the input PDF and hence is using the default resolution of 72x72dpi as shown in the convert -verbose 0038.pdf out.pdf output:

[ghostscript library] -q -dQUIET (...) "-r72x72" (...)

You applied the correct option -density 300, but as an output option, i.e. after the input file name. Indeed most options for convert are output options, but man convert knows that

(...) a limited number of setting are input-option. They include: -antialias, -caption, -density, -define, -encoding, -font, -pointsize, -size, and -texture as well as any of the miscellaneous options.

So, the correct convert command should be:

convert -density 300 0038.pdf -brightness-contrast 0x10% out.pdf

Finally, two remarks:

  • I would employ a lossless compression like -compress LZW; the -quality option is for JPEG/MIFF/PNG compression only.

  • -brightness-contrast probably won't work on b/w documents and does not affect the anti aliased screen display of some PDF readers for that kind of files. (Typically for scanned journal articles.)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .