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:

enter image description here

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:

This is a test... 0123456789

Thank you in advance!

  • How do you know the PNG is not just showing up on screen at a bigger size? If you mean that the font size has increased relative to the size of the page, then that almost defeats the point of PDF (Portable Document Format), so I doubt that's happening. If you mean that the entire page is being displayed at a bigger size (and not just the text on the page), then that's a different question. Which is it? – ShreevatsaR Feb 10 '18 at 2:15
  • Thank you for the quick response! I think that the PNG is not showing up at a bigger size because when I open it in the image viewer (I am using gwenview for this) I set the zoom factor to 100% (this way I believe to keep a 1=1 match between image and screen pixels... I've done the same for the PDF and Libreoffice... set the zoom to 100%). – Christian Pagot Feb 10 '18 at 2:25
  • (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
  • @ShreevatsaR I have jut made a quick test: I've set density to 96 dpi in convert, and now the fonts on the png file seem to have the same size as those on the pdf (both viewed at 100% zoom). I have then run the command "$ xrdb -query", and verified that Linux (Ubuntu 14.04) sets the dpi to 96 (Xft.dpi: 96), although the actual dpi is ~112. I think the problem is that the dpi seems to be fixed, despite the actual density of the display. I will not include it as an answer because I am not expert on this, and I may be totally wrong. – Christian Pagot Feb 10 '18 at 2:53
  • 1
    The PNG doesn't have any fonts and so doesn't have any font size. It is just a picture with no font information whatsoever. I don't really understand what you want to do here. What will happen when somebody opens the file on a screen with a different DPI? If it worked as you want, it would then be an entirely different size, so how would you be keeping it consistent? Even if it worked on your screen, it would fail elsewhere, surely? – cfr Feb 10 '18 at 2:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.