Converting a PDF to JPG (using ImageMagick)
·
421 words
·
2 minutes read
In the example below we use the gographics/imagick
package as a wrapper to the C library for ImageMagick to convert our PDF into a JPG. The processes goes as follows: We use the package to load in our test file which we then process by setting the resolution, compression levels and alpha channel settings then we save the final output file. Because the library is built on C, it’s important we call the Terminate
and Destroy
functions appropriately to keep our memory usage in check.
This is a useful process for creating thumbnails or converting the files to show in the web browser. It is limited to the first page of the PDF at the moment though.
Prerequisites for running under Ubuntu 18.04:
|
|
The code:
|
|
If you see an error like below, take a look at this guide.
|
|