To reduce white/blank space around text when converting from PDF to PNG, you can use the -trim
option in ImageMagick
, which will remove unnecessary spaces. Here is the command you can try:
convert -density 300 -trim file.pdf -quality 100 -sharpen 0x1.0 name_file_out.png
In this command, -density 300
will set the resolution, -trim
will remove whitespace, -quality 100
will ensure the quality of the image, and -sharpen 0x1.0
will make the text clearer.
If your PDF file has a different CropBox definition than a MediaBox and you want to use CropBox to remove spaces, you can add the -define pdf:use-cropbox=true
option to the ImageMagick
command as follows:
convert -define pdf:use-cropbox=true file.pdf name_file_out.png
This command will indicate that you want to use the CropBox size defined in the PDF file, helping to remove unwanted spaces.
If you’re still having problems with space, it’s possible your PDF file has a problem with page size definition. In that case, you may need to edit the PDF file before converting or use image editing tools after conversion to trim the space. Make sure you have ImageMagick and Ghostscript installed on your system to use these commands.