Converting PDFs to JPGs shrinks the text.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
web.lewis
Posts: 6
Joined: 2015-09-16T12:16:56-07:00
Authentication code: 1151

Converting PDFs to JPGs shrinks the text.

Post by web.lewis »

Hello all,

My project generates a PDF file, but needs to display a low resolution JPG for the user to approve. I'm using PHP and TCPDF to generate the PDF files and everything is working great there. All the elements are placed in the correct location and at the correct size. However, after a run the command:

exec('/usr/bin/convert -density 600 '.$file_path. -colorspace RGB -resample 300 -quality 90 '.$new_file_path);

the resulting JPG has all the elements in the correct location, but the text is less than half the size it should be.

Here is an example of the PDF being generated (The result I'm looking for): http://goo.gl/IAxrEi
And here is what the resulting JPGs look like (Not quite what I need): http://goo.gl/Dkm0Kc
** Notice the text at the bottom. **

After spending a day Googling this, the only things I've dug up is stuff on the -density & -pointsize settings. The -density setting only seems to affect the text clarity. The default setting will generate text that is very pixelated while a higher setting generates clean and crisp text, but no value seems to generate the text at the correct font size. As far as the -pointsize setting, I have had no luck with any value changing the font size.

What am I missing?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Converting PDFs to JPGs shrinks the text.

Post by Bonzo »

Have you tried converting a pdf created with some different software ?

What version of Imagemagick are you using? If it is a standard buid version from the operating system install on a server it could be years out of date.
web.lewis
Posts: 6
Joined: 2015-09-16T12:16:56-07:00
Authentication code: 1151

Re: Converting PDFs to JPGs shrinks the text.

Post by web.lewis »

Bonzo wrote:What version of Imagemagick are you using? If it is a standard buid version from the operating system install on a server it could be years out of date.
The company we have our web hosting through has version 6.5.4-7 installed. Is that too outdated?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDFs to JPGs shrinks the text.

Post by fmw42 »

370 versions old. current is 6.9.2.1
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Converting PDFs to JPGs shrinks the text.

Post by Bonzo »

The company we have our web hosting through has version 6.5.4-7 installed. Is that too outdated?
I think that is the standard Centos 5 install version.

I would first install Imagemagick localy and try it and if it works OK ask your hosts to update Imagemagick. If they do not want to do that I would move hosts as there are a lot about who would update if asked.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDFs to JPGs shrinks the text.

Post by fmw42 »

I am not sure what your issue is. The resulting file is much larger than the original. Is that what you want? Is it a printing issue or an image size issue?

Code: Select all

convert -density 600 -colorspace RGB ca5343423185a848.pdf -resample 300 -quality 90 ca5343423185a848.jpg
identify ca5343423185a848.pdf ca5343423185a848.jpg
ca5343423185a848.pdf PDF 900x684 900x684+0+0 16-bit Bilevel Gray 77.4KB 0.000u 0:00.000
ca5343423185a848.jpg[1] JPEG 3750x2850 3750x2850+0+0 8-bit sRGB 1.294MB 0.000u 0:00.000

Perhaps you just want to resize rather than resample and then set the density as needed?
web.lewis
Posts: 6
Joined: 2015-09-16T12:16:56-07:00
Authentication code: 1151

Re: Converting PDFs to JPGs shrinks the text.

Post by web.lewis »

fmw42 wrote:I am not sure what your issue is. The resulting file is much larger than the original. Is that what you want? Is it a printing issue or an image size issue?
It's a printing issue. If you compare the text at the bottom of the PDF to the text at the bottom of the JPG you'll notice that the JPG's text is significantly smaller than what it should be. I've tried outputting the JPG at different sizes, but the text always comes out too small.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting PDFs to JPGs shrinks the text.

Post by snibgo »

When I download the PDF and convert it ...

Code: Select all

convert ca5343423185a848.pdf x.png
... the text size, in proportion to the image size, is exactly as Adobe Reader shows it.

This is with IM 6.9.1-6 and Ghostscript 9.15.

My result is different to the OP result http://tropicbeauty.buildyourcalendar.c ... 5e9867.jpg .

I suggest updating the software -- both IM and GS.
snibgo's IM pages: im.snibgo.com
web.lewis
Posts: 6
Joined: 2015-09-16T12:16:56-07:00
Authentication code: 1151

Re: Converting PDFs to JPGs shrinks the text.

Post by web.lewis »

snibgo wrote:I suggest updating the software -- both IM and GS.
As both Bonzo and snibgo suggested, I've asked our hosting company to upgrade both IM and GS. After some back and forth they agreed to to this, and installed version 6.9.2-1 of IM, and version 9.16 of GS.

However, now I'm running into a new problem. I can convert a JPG to a PNG and vise versa, but when I try to convert a PDF to anything I get nothing. From my research this means that IM is not locating the GS to do so. Am I correct, and if so what do I need to do to correct this?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Converting PDFs to JPGs shrinks the text.

Post by fmw42 »

There have been reports of issues with GS 9.16 and people downgrading to GS 9.15 have found the latter works.
web.lewis
Posts: 6
Joined: 2015-09-16T12:16:56-07:00
Authentication code: 1151

Re: Converting PDFs to JPGs shrinks the text.

Post by web.lewis »

fmw42 wrote:There have been reports of issues with GS 9.16 and people downgrading to GS 9.15 have found the latter works.
Rolled GS back to 9.15, and I'm still having no luck. I'm running:

exec('/usr/local/bin/convert '.$path_for_PDF.' -verbose -identify '.$path_for_JPG, $output, $return);

When I echo $output I get an empty array ( array(0) {} ), and $return has a value of 1. I don't get any warnings or errors, but there is no JPG version of the PDF I'm trying to convert.

I've put in a request to roll IM back to 6.9.1-6 to try and match the conditions snibgo used to get their results. I don't know, but I'm starting to think that this issue is more than just a simple version upgrade. Any other ideas?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting PDFs to JPGs shrinks the text.

Post by snibgo »

I don't use PHP. There are some threads on these forums about getting Ghostscript to be callable from IM under PHP.

Some things you might try:

1. Does the command run from the command line?

2. Add "-verbose" to the command, before reading the PDF. The text output may indicate a problem.

3. Add "-debug all" to the command, before reading the PDF. The text output may indicate a problem.
snibgo's IM pages: im.snibgo.com
web.lewis
Posts: 6
Joined: 2015-09-16T12:16:56-07:00
Authentication code: 1151

Re: Converting PDFs to JPGs shrinks the text.

Post by web.lewis »

snibgo wrote:There are some threads on these forums about getting Ghostscript to be callable from IM under PHP.
After some digging I came across one thread on this forum that contained the link: http://www.veryinteractivepeople.com/?p=521. It took me to an article where the author wrote a PHP script to convert a folder of PDFs to JPGs. I simplified the author's script to the following:

$pdf = 'path_to_pdf';
$quality = 90;
$res = '96x96';
$jpg = 'path_for_jpg';

exec("'/usr/local/bin/gs' '-dNOPAUSE' '-sDEVICE=jpeg' '-dUseCIEColor' '-dTextAlphaBits=4' '-dGraphicsAlphaBits=4' '-o$jpg' '-r$res' '-dJPEGQ=$quality' '$pdf'");

and it produces a JPG file with text at the correct size.

Thank you everyone for all the help.
Post Reply