thuelsing.de THUELSING.DE

Techstuff, programming and galleries

Convert PDF to JPG in high quality

I worked a lot with latex and was really happy about the possibility to include pdf in documents as vector graphics. Zooming into the document won't result in an aweful blurry something, but in clear pictures.

However, being forced to move to powerpoint, I need a workaround. The usual: Copy to clipboard from adobe reader produces sh*** results. Therefore, I needed another solution. And here it is:

You'll need imagemagick (get it from http://www.imagemagick.org/)
You need the windows powershell (should be installed)
Run powershell as administrator
Call "Set-ExecutionPolicy RemoteSigned", or if you are fearless and the previous didn't work "Set-ExecutionPolicy Unrestricted"
Check if you already have a $PROFILE with "Test-Path $Profile"
If not, create it: "New-Item -path $profile -type file -force"
Add the following functions to the $PROFILE (open it with "notepad $PROFILE$"):

function pdf2jpg($in)
{
    $out = $in -replace "pdf","jpg"
    convert -units PixelsPerInch -density 150 -trim $in -quality 100 $out
}

function batchconvert { Get-ChildItem . -Filter *.pdf | Foreach-Object {pdf2jpg $_} }

 

Open a new powershell or load the file via .$PROFILE

​Now, you can run pdf2jpg filename.pdf to convert the pdf to a jpg of reasonable size and good quality. To convert all pdf files in your current directory, run batchconvert.

If the quality isn't good enough, you can play around with the quality and density settings. For plots, these settings were  a good balance between filesize and quality.

Enjoy!