LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-21-2009, 09:53 AM   #1
privet
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Rep: Reputation: 0
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!

Last edited by privet; 01-21-2009 at 10:14 AM.
 
Old 01-21-2009, 12:39 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 01-21-2009, 04:56 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 01-22-2009, 01:06 PM   #4
privet
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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
 
Old 01-22-2009, 01:30 PM   #5
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
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
 
Old 01-23-2009, 03:04 AM   #6
privet
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
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!
 
Old 01-27-2009, 02:29 AM   #7
privet
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
list on converted pics

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...
Attached Thumbnails
Click image for larger version

Name:	pdf2pic_list.jpg
Views:	36
Size:	91.4 KB
ID:	35  
 
Old 01-27-2009, 09:10 AM   #8
privet
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
pdf2jpg demo files

in attachments are my
input-file (_table_0.pdf) and
output-file (table_0.jpg)

still looking for a solution for this strange behaviour...
Attached Thumbnails
Click image for larger version

Name:	table_0.jpg
Views:	25
Size:	84.2 KB
ID:	40  
Attached Files
File Type: pdf _table_0.pdf (8.4 KB, 21 views)
 
Old 02-02-2009, 12:33 AM   #9
privet
LQ Newbie
 
Registered: Jan 2009
Posts: 6

Original Poster
Rep: Reputation: 0
i found the solution:
used the newest Ghostscript (8.63) instead of version 8.00 solved the problem!
 
Old 03-04-2010, 03:56 PM   #10
fabienhenon
LQ Newbie
 
Registered: Mar 2010
Posts: 3

Rep: Reputation: 0
Pdf to jpf

Quote:
Originally Posted by privet View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding high quality Linux Video kstan Linux - General 1 03-16-2008 11:53 AM
recommend high quality webcam gothicbob Linux - Hardware 2 05-22-2007 04:33 PM
High Quality Streaming with Xine littletom Linux - Software 5 02-08-2005 04:38 PM
High Quality Thermal paste crewblunts General 5 07-19-2004 12:55 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration