# PDF to PNG to PDF on macOS using ImageMagick

[ImageMagick](https://imagemagick.org/index.php) is an awesome command line tool for working with images.

## Convert PDF to PNG files with magick

Convert a multi-page PDF file to PDFs with ImageMagick using the following command:

```bash
magick density -300 input.pdf -resize 30% outdir/output.png
```

You can adjust the density and resize values for your preferred file size and quality.

## Combine PNG files to PDF in Finder

Select all output PNG files, right click, go to Quick Actions → Create PDF.

## Improving this

### Can this be done with just ImageMagick?

I did attempt the following command but the images were smaller than ideal.

```bash
cd outdir
magick *.png -scale 1311x1819 \
    -units PixelsPerInch \
    -density 300x300 output.pdf
```

Doing it all with ImageMagick would make this easier to script.

## References

* [https://stackoverflow.com/a/18863052](https://stackoverflow.com/a/18863052)
    
* [https://imagemagick.org/discourse-server/viewtopic.php?t=26548](https://imagemagick.org/discourse-server/viewtopic.php?t=26548)
    
* [https://www.imagemagick.org/discourse-server/viewtopic.php?t=35159](https://www.imagemagick.org/discourse-server/viewtopic.php?t=35159)
