Page 1 of 1

Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-16T12:56:33-07:00
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?

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-16T13:01:18-07:00
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.

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-16T13:47:55-07:00
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?

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-16T13:54:50-07:00
by fmw42
370 versions old. current is 6.9.2.1

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-16T14:00:05-07:00
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.

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-16T14:03:04-07:00
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?

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-17T05:43:57-07:00
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.

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-17T08:27:38-07:00
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.

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-18T13:26:14-07:00
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?

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-18T13:55:41-07:00
by fmw42
There have been reports of issues with GS 9.16 and people downgrading to GS 9.15 have found the latter works.

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-22T06:38:12-07:00
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?

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-22T06:46:32-07:00
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.

Re: Converting PDFs to JPGs shrinks the text.

Posted: 2015-09-22T10:23:59-07:00
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.