Page 1 of 1

failing to convert specific pdf to png

Posted: 2016-08-26T10:11:49-07:00
by kellyfelkins
ImageMagick 6.9.5-7
Ghostscript 9.10

I have a rails app using the paperclip gem running on Heroku. It successfully converts most pdfs, generating thumbnails. One pdf is not converting but no error is generated.

Code: Select all

Command :: file -b --mime '/tmp/9d490e3a2db6fb7ca420a9b37a5e18a320160825-299-1fs6wtc.pdf' 
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/9d490e3a2db6fb7ca420a9b37a5e18a320160825-299-1wvia8y.pdf[0]' 2>/dev/null 
Command :: convert '/tmp/9d490e3a2db6fb7ca420a9b37a5e18a320160825-299-1wvia8y.pdf[0]' -auto-orient -resize "400x400>" '/tmp/c45b9e1aa5fd7045253736db8cce157120160825-299-xo8iop.png' 
Command :: file -b --mime '/tmp/9d490e3a2db6fb7ca420a9b37a5e18a320160825-299-125tp7b.pdf' 
[paperclip] saving /documents/10850/original/Hershey_Hiring_in_San_Leandro.pdf 
[paperclip] saving /documents/10850/small/Hershey_Hiring_in_San_Leandro.png 
The original document is available at:
http://files.justmyneighbors.com/docume ... eandro.pdf

Any ideas?

Thank you.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T11:58:33-07:00
by snibgo
For me, IM 6.9.2-5 with Ghostscript 9.15, the PDF document converts but most text is strange (perhaps using a wrong font).

There is something strange about that PDF. Adobe Reader can display it, and it looks okay, but try copying text from it. The text highlighting is wrong, and the copied text is junk.

Maybe there is a problem that the Ghostscript people can fix.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T13:40:55-07:00
by GeeMack
kellyfelkins wrote:The original document is available at:
http://files.justmyneighbors.com/docume ... eandro.pdf

Any ideas?
Using IM7 on Windows 10 and converting the PDF with this command...

Code: Select all

magick -density 1200 -background white ^
   Hershey_Hiring_in_San_Leandro.pdf -flatten Hershey_Hiring_in_San_Leandro.png
I get what appears to be a near perfect result. Most of the document is in a font that is named Calibri on my system. My ghostscript version is "GPL Ghostscript 9.18 (2015-10-05)".

ETA: The PDF file opens in my Adobe Reader version 11.0.10 and looks good. But as snibgo mentioned, if I select some text and copy it, it pastes as some really odd strings of characters.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T14:02:31-07:00
by snibgo
GeeMack is usually right about such things, so I downloaded GS 9.19. Sure enough, it converts the Hershey document, with IM v6.9.5-3.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T14:23:36-07:00
by kellyfelkins
What a great community! Thanks everyone...still have the problem but I certainly appreciate people investigating.

This is result of the resize/convert operation: http://files.justmyneighbors.com/docume ... 1472228345

It appears to be a transparent image of the proper size.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T14:25:25-07:00
by kellyfelkins
One of my registered users uploaded the document. Apparently it was in Word format and she converted it to pdf.

I'll see if I can find a ghostscript message board.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T14:32:14-07:00
by fmw42
I have heard problem with GS 9.18 before, that is why I have kept at 9.16. So it seems they may have those fixed in 9.19.

Re: failing to convert specific pdf to png

Posted: 2016-08-26T15:30:11-07:00
by GeeMack
kellyfelkins wrote:It appears to be a transparent image of the proper size.
Did you make sure to set a background color and flatten the image. If I just run a straight through conversion like this...

Code: Select all

magick -density 1200 Hershey_Hiring_in_San_Leandro.pdf Hershey_Hiring_in_San_Leandro.png
... I get the basic document but with a transparent background except behind certain areas of text. When I give it a white background and flatten the PDF like this...

Code: Select all

magick -density 1200 -background white ^
   Hershey_Hiring_in_San_Leandro.pdf -flatten Hershey_Hiring_in_San_Leandro.png
... it gives me the full document on white.

I always use "-density 1200" ahead of the input filename when converting PDFs to get a very clear image when reducing it to any size from there. Without a density setting the default 72dpi result is generally unusable, but a density setting of 600 or even 300 is way faster than "-density 1200", makes a much smaller file, and is probably quite usable for most purposes.

Re: failing to convert specific pdf to png

Posted: 2016-08-27T15:08:52-07:00
by kellyfelkins
I resolved this by updating ghostscript. I did this via the buildpack mechanism on Heroku.

Ghostscript 9.16
ImageMagick 6.9.5-7 Q16 x86_64 2016-08-26

Code: Select all

$ heroku buildpacks
=== justmyneighbors Buildpack URLs
1. https://github.com/ello/heroku-buildpack-imagemagick
2. https://github.com/heroku/heroku-buildpack-ruby
3. https://github.com/bvirlet/heroku-buildpack-ghostscript.git
Thanks for your help.