Convert PDF to png like Xcode does during compilation

468 Views Asked by At

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)...

0

There are 0 best solutions below