5

I've been trying to use LaTeX to generate some well formatted text blocks, so I can composite them together with images using ImageMagick. (I'm building cards for a card game. Mostly graphics, but a few blocks of text that have to look nicer than ImageMagick will reliably format them.)

Unfortunately, LaTeX is outputting PDFs with an implied DPI of 72 in the metadata. So when I try to composite them in with 300dpi graphics in ImageMagick, they come out tiny. If I tell ImageMagick to upscale them, it still reads them in at 72dpi, then enlarges that, and all the text looks hideously pixelated.

Behold the pixelation

Using mdls, I might have found one clue seems to be in the metadata:

kMDItemPageHeight                  = 85.039
kMDItemPageWidth                   = 141.7319946289062

(This is a 50mm x 30mm document. At first I was thinking that the kMDItemPageWidth proved the pdf was being written at 72 dpi. But on looking into it, this metadata is setting the size of the document in points, not pixels. So this may not be the clue I thought it was.)

How do I get LaTeX to set that metadata, or otherwise construct the pdf file, so that when ImageMagick opens it, it's going to honor that the intended resolution is 300dpi instead of the 72dpi that's currently being written into the metadata?

5
  • Welcome to TeX.SE.
    – Mico
    Commented Mar 23, 2023 at 3:54
  • Thanks. So much to learn.
    – baudot
    Commented Mar 23, 2023 at 4:03
  • Perhaps \pdfimageresolution=300 will help (in Preamble). But actually, it should not make a difference for your purpose. You can command ImageMagick to disregard whatever the PDF says, as long as the images and text are vector. You can also import a PDF page into a graphics app, such as GIMP, and tell it whatever resolution you like, when it imports the file.
    – user287367
    Commented Mar 23, 2023 at 4:43
  • So far the workaround is to use pdftoppm with the -jpeg and -r 300 flags set, instead of ImageMagick, for the initial conversion from pdf to jpeg.
    – baudot
    Commented Mar 23, 2023 at 4:45
  • 1
    Out of curiosity: which fonts are you using? And are they scalable? (for example MikTeX is known to not use a scalable version of the default font, whereas TeXLive does). If it is scalable then Marcels suggestion should work just fine. I often use a density of 1200 and then scale it down.
    – daleif
    Commented Mar 23, 2023 at 8:55

1 Answer 1

7

PDFs don't contain any DPI in the metadata, the assumed 72dpi come from ImageMagick. You can instruct ImageMagick to use another density by passing -density before the PDF file:

# Combines image.png and page.pdf at 72 dpi:
magick composite -geometry +300+300 image.png page.pdf output.png

# Combines image.png and page.pdf with PDF loaded with 300 dpi instead:
magick composite -geometry +300+300 image.png -density 300 page.pdf output.png

1
  • This is how I'm getting the horribly pixelated image shown above.
    – baudot
    Commented Mar 23, 2023 at 23:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .