# Converting PDF to PNG changes fontsize

I am writing an python-based OpenGL application that will present some text and math on the screen. These textual elements will be presented in the form of texturized quads. However, I am having trouble with the font sizes in the textures: they are larger than they should eventually be.

In order to generate the text and math texture images that will be mapped on those quads, I am doing the following:

1. I generate a pdf file from the latex source with pdflatex. The command used at this step is: $pdflatex sample.tex 2. I generate a png image file from the pdf with Imagemagick's convert. That's the current command line used at this step: $ convert -set units PixelsPerInch -density 112 sample.pdf -quality 100 sample.png

The png file is then generated, and I could successfully map it on the quads. However, I've noticed that the font size of the png file does not match that of the pdf. In order to check it, I've rendered the same sample string on: a pdf (with pdflatex); a Libreoffice document; and on a png image file (generated with convert applied over the pdf). That's what I have got:

The topmost sentence was extracted from the pdf. The sentence in the middle was generated by Libreoffice. The sentence at the bottom (the larger one) was extracted from the png file generated from the pdf with convert. For the two first samples I've used a 10pt Computer Modern font.

The results from pdf and Libreoffice are almost identical (the Libreoffice is actually a little bit shorter). I was expecting to get something very similar with the png file (the -density option of convert was set to 112 to match that of my computer screen). However, that string is much larger than the other two.

My questions are: Is it possible to convert a pdf file into a png such that the font-size is kept identical? If yes, how?

Below is the Latex sample file I've used for the test above:

\documentclass[10pt]{standalone}
\usepackage[dvipsnames]{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{lmodern}
\begin{document}
\pagecolor{white}
This is a test... 0123456789
\end{document}


• (Welcome to TeX.SE BTW.) Just a hunch: try 96dpi instead of 112. (Not sure where the 112 comes from exactly, but 96 is a kind of standard assumed by many software applications.) In any case, this does not seem a problem with the TeX side of things (I'm assuming that when you open the PDF in your PDF viewer, things are fine), but with Imagemagick (the convert program). – ShreevatsaR Feb 10 '18 at 2:44