LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   pdf2jpg in high quality but small width (https://www.linuxquestions.org/questions/linux-software-2/pdf2jpg-in-high-quality-but-small-width-698881/)

privet 01-21-2009 09:53 AM

pdf2jpg in high quality but small width
 
Greetings,

not really a big bug, but an enhancement possibility:

I try to convert PDF to JPG to be able to reference the created picture in a html-file.

I convert my PDF to JPG with a call like
gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=jpeg -sOutputFile=my.jpg
(working on winXP)

My PDF contains text in tables.

The output-pic is hardly readable embedded in the html-file.

Problems/Limitations:
1. the created JPG-picture shouldn't be bigger than width=600px (height is not important)
to avoid scrolling
2. the created JPG should be pin sharp to be readable

I've tried several ghostscript-parameters to get a small but sharp JPG-image, like
- r300 (the file will be much too big)
- sPAPERSIZE=a4/a5/letter
- dDEVICEWIDTHPOINTS, dDEVICEWIDTH, dDITHERPPI

but without success: the created JPG-file is hardly readable!

Could you please, tell if there is a combination to create small+sharp JPGs
(if yes, which call is to set to create a SHARP JPG WITH MAX-WIDTH=600px ?)

Thanks in advance!

jlinkels 01-21-2009 12:39 PM

Basically:
Code:

convert -geometry 600  -quality 90 -myfile.pdf myfile.jpg
or enhance it with:

Code:

convert -geometry 600  -quality 90 -unsharp 0.7x1.1+2.0+0 nhk.pdf nhk.jpg
600 pixels is pretty small. With this conversion I converted a pdf document in 10pt font, and it is perfectly legible.
Convert is a part of the ImageMagick suite.

jlinkels

jlinkels 01-21-2009 04:56 PM

Additonally, you could cut the margins off the sides while converting. Showing white margins does add to the size, but not to the information. It is done with ImageMagick convert as well.

convert -geometry 800 -shave 100x0 -quality 90 myfile.pdf myfile.jpg

This will first convert the picture to a width of 800 px, and then shave 100 px off at each side

jlinkels

privet 01-22-2009 01:06 PM

convert.exe instead of gs
 
convert.exe from imagemagick is great!
It creates pics from every page of the pdf-file in whatever size I want!

The parameter are curious, I was trying to play with them:

1. -geometry works perfekt
2. -quality doesn't seem to work. Using numbers from 90 til 990
no changes in the output picture
3. -unsharp Still not understood what this parameter does...

I'm still trying a good combination for getting a very sharp picture
(my pdf contains text in tables).

The size of the output picture doesn't matter...

Do you have any idea for getting a very sharp image;
what would be the best parameter-chain?

Thanks in advance

jlinkels 01-22-2009 01:30 PM

There is very eleborate user manual on-line for Imagemagick at imagemagick.org

The parameter chain is the best I could find for you. The UNsharp filter performs sharping, really. The problem is that it removes the anti-aliasing effect, which is less pleasant to the eye. Look for "unsharp filter" in Gimp, it is the same mask, but the parameters are different.

In Imagemagick: -unsharp 1.2x0.7+2.0+4.0
1.2x0.7 is the mask size in pixels with 0.7 the deviation
2.0 is the unsharp percentage, called 200% in Gimp
4.0 is the treshold, wouldn't use it, it is for not increasing the noise in pictures.

You might want to reduce the percentage for better antialiasing.

Quality ranges from 0-100. Above 90% you won't notice much improvement. Below 80% you'll start to see artifacts.

You might also try to save the picture as GIF (simply change the detsination file name to .gif) and see what the effect is.

jlinkels

privet 01-23-2009 03:04 AM

convert parameters
 
I think, I have now the parameters for the best output from my pdf-files:
-----------
convert -trim -posterize 9 +matte -geometry 650 -linewidth 1 -identify -enhance +dither -colors 16 +contrast +contrast -density 88 -black-point-compensation -quality 100 -unsharp 0.7x1.1+2.0+0 2.pdf 2.jpg
-----------

very helpful parameters:

-trim: crops white margins
-geometry: works perfectly
-colors 16: I don't need all colors, because I have only text in tables

Thanks for helping me!

privet 01-27-2009 02:29 AM

list on converted pics
 
1 Attachment(s)
I still have a little flaw while converting lists from PDF to JPG
(see attached picture)...

How could I avoid these big black squares and have instead a normal little dot as list-mark?

Any ideas?

For a hint thanks in advance...

privet 01-27-2009 09:10 AM

pdf2jpg demo files
 
2 Attachment(s)
in attachments are my
input-file (_table_0.pdf) and
output-file (table_0.jpg)

still looking for a solution for this strange behaviour...

privet 02-02-2009 12:33 AM

i found the solution:
used the newest Ghostscript (8.63) instead of version 8.00 solved the problem!

fabienhenon 03-04-2010 03:56 PM

Pdf to jpf
 
Quote:

Originally Posted by privet (Post 3428734)
i found the solution:
used the newest Ghostscript (8.63) instead of version 8.00 solved the problem!


This is the bash script I use to encode pdf as jpg on my PMP photo viewer

8<------------snip------------------>8

#!/bin/bash
pdftoppm The_War_of_the_Worlds_NT.pdf -gray war
for i in $( ls *.pgm ); do
convert $i -trim -negate -rotate 90 $i.jpg
echo $i
done
rm -f *.pgm

8<-----------snap------------------->8

1 pdftoppm creates multiple pgm files ( as many as the pages found in the pdf)
2 convert (from imagemagick trims, then inverts the black and white image, then rotate the image
3 all the pgm files are deleted


All times are GMT -5. The time now is 06:54 PM.