failing to convert specific pdf to png

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
kellyfelkins
Posts: 4
Joined: 2016-08-26T09:59:49-07:00
Authentication code: 1151

failing to convert specific pdf to png

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: failing to convert specific pdf to png

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: failing to convert specific pdf to png

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: failing to convert specific pdf to png

Post 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.
snibgo's IM pages: im.snibgo.com
kellyfelkins
Posts: 4
Joined: 2016-08-26T09:59:49-07:00
Authentication code: 1151

Re: failing to convert specific pdf to png

Post 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.
kellyfelkins
Posts: 4
Joined: 2016-08-26T09:59:49-07:00
Authentication code: 1151

Re: failing to convert specific pdf to png

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: failing to convert specific pdf to png

Post 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.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: failing to convert specific pdf to png

Post 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.
kellyfelkins
Posts: 4
Joined: 2016-08-26T09:59:49-07:00
Authentication code: 1151

Re: failing to convert specific pdf to png

Post 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.
Post Reply