1

I have some assets in my iPhone app which are in PDF. Xcode automatically converts them to pngs of appropriate size. However, I need to include these in my android app. So, I want to take the PDF and produce 2 variants of pngs for my Android app.

I was trying to convert PDF to png using sips. Unfortunately, I cannot control the resulting size. I was trying to achieve this using the dpiHeight/dpiWidth parameters, but they seem to have no effect.

Two lines below produce the png of exact same size and it is driving me crazy:

sips -s dpiHeight 300 -s dpiWidth 300 -s format png TS4612.pdf --out out.png

and

sips -s dpiHeight 150 -s dpiWidth 150 -s format png TS4612.pdf --out out.png

Any help is greatly appreciated! If anyone knows how to achieve what I want using other methods I am up for suggestions. Xcode does it somehow so I am pretty sure that I should be able to also do it on my mac.

Update

It is possible to obtain correct size using ImageMagick command. For example:

convert -density 576 -quality 100% TS4612.pdf -resize 25% out.png

However, the resulting quality is not great. If I compare it to the output of sips (matching the resolution) then I do notice that sips produces image of higher quality. If only I could control its density (hence size)...

Andriy Gordiychuk
  • 6,163
  • 1
  • 24
  • 59
  • -quality 100 is not typical of png compression in Imagemagick and should come after reading the pdf and after the resize. See http://www.imagemagick.org/script/command-line-options.php#quality. If the pdf contains a raster image, then you may want to use pdfimage to extract the raster image from the vector shell – fmw42 May 07 '17 at 23:53
  • @fmw42 thanks for your input. The PDF in question contains vector graphic, not a raster image. – Andriy Gordiychuk May 08 '17 at 00:04
  • Will try rearranging the arguments and will get back – Andriy Gordiychuk May 08 '17 at 00:06
  • For ImageMagick 6, rearranging likely won't make a difference. But the -quality value should, if you use the reference I provided to pick a more optimum value. What version of ImageMagick are you using? – fmw42 May 08 '17 at 01:43

0 Answers0