Tuesday, July 19, 2016

Extracting images from a PDF

This example worked well for an example created by the Android Cam Scanner app, which I use to document and scan quite a lot.

convert -verbose -density 150 -trim -sharpen 0x1.0  -quality 100 ../1103-front-panel-card-ba11.pdf 1103.jpg


from recommended solution from above link saved to make sure it doesn't vanish

173 vote

It appears that the following works:
convert           \
   -verbose       \
   -density 150   \
   -trim          \
    test.pdf      \
   -quality 100   \
   -sharpen 0x1.0 \
It results in the top image Compare this to the result of my original command (image on the bottom):

(To really see and appreciate the differences between the two, right-click on each and select "Open Image in New Tab...".)
Also keep the following facts in mind:
  • The worse, blurry image on the right has a file size of 1.941.702 Bytes (1.85 MByte). Its resolution is 3060x3960 pixels, using 16-bit RGB color space.
  • The better, sharp image on the left has a file size of 337.879 Bytes (330 kByte). Its resolution is 758x996 pixels, using 8-bit Gray color space.
So, no need to resize; add the -density flag. The density value 150 is weird -- trying a range of values results in a worse looking image in both directions!


No comments:

Post a Comment