0

I generated a PDF with a row of chars M. Every M had consistent width, but the distance between each was changing: first couple was 2px, the fifth one had 3px, then the next four had 2px, the tenth 3px, etc.

Since there is absolutly no difference in any of the M's or any spaces inbetween in my code, only conclusion is that some width value could not scale properly in coordinate system generating an extra pixel every so often.

This is how PDF calculates how much to move horizontally when a glyph is painted:

enter image description here

When calcualting for a standard 96DPI display, each pixel is represented by 0.75 unit (checked and tested thoroughly).

Having that in mind, I need to make sure that Tx value is divisible by 0.75.

This is what I know:

  1. w0 is an integer originating from widths array (widths[])
  2. Tfs is a nubmer divisible by 0.75 (set by me)
  3. Th is 100 (default)
  4. Tc and Tw are both 0 (default)

So Tj/1000 needs to be an integer, meaning Tj needs to be divisible by 1000.

One way is to get and adjust the Tj value. Another approach to this is to acces the Tx value once it's calcualted and just change it to closest value divisible by 0.75.

How do I do this in iText?

Or is my whole assumption wrong?

Source: link (page 252)

Karlovsky120
  • 6,212
  • 8
  • 41
  • 94
  • *How do I do this in iText?* - Most likely your T_j value always is 0. Please provide the PDF in question to make sure. – mkl Sep 18 '13 at 08:04

1 Answers1

1

I have seen this question asked before here on SO and I really do not understand what your are trying to achieve. If you drew the M letters at equal distances then they will be displayed at equal distances. What you are experiencing is a limitation of the display technology and it is caused by pixel fitting.
Creating a PDF file to be displayed pixel perfect at 96dpi is not something the PDF format was designed for. Even if you create such a PDF file that is displayed as you expect in one viewer, you have no guarantee that it will be displayed the same in another viewer.

Mihai Iancu
  • 1,818
  • 2
  • 11
  • 10
  • I want everything to be to scale. It doesn't matter if letters are wider for someone else, everything else will be wider and look as it should. As is, some lines tend to extend over margins of a page, if not over the edge, which doesn't work for me. I asked it several times, but each time I deleted the last question and added new stuff I learned. This thing DID work for when I was trying to figure out vertical coordinates. Now I need to somehow make it work for horizontal ones, by manipulating font and it's attributes... – Karlovsky120 Sep 18 '13 at 00:08
  • Use a formatting the engine that works in the scale you need. One meant for print output. Everything has a limitation in the way it works internally and manages positions of information internally. – Kevin Brown Sep 18 '13 at 04:46