2

I'm given a special font with numbers like that:

default font and number rendering

As you can see on the 3 for example, some numbers descent below the baseline. What I like to achieve is, that these numbers don't go below the line and that it looks like this:

requested number rendering

In Word this can be easily set in the character settings for the same font. How can one render digits in TCPDF like this? I'm totally stuck there and have no clue how to proceed.

Cheers for any help!

datort
  • 71
  • 4
  • Try to set style vertical-align:bottom; – Vinay Feb 13 '17 at 10:32
  • I'm not working with HTML/CSS to create the PDFs. Text is placed and written with the TCPDF->Cell() method. – datort Feb 13 '17 at 11:00
  • Are you sure that you don't want the numbers to descend below the baseline? That's a characteristic of the font, and part of what gives it its individuality. I know this isn't very helpful :-) but to be honest I don't think what you want is easily done without very fiddly coding. – Ray O'Donnell Feb 13 '17 at 11:53
  • @ray: I would be totally fine with the font as it is. The thing is, our customer wants it this way. It's part of their CI so the generated PDF must meet their specifications. – datort Feb 13 '17 at 12:43
  • @datort: Fair enough. Are they absolutely fixed on using that particular font? Could you substitute a similar one, perhaps just for numbers? I realise you've probably been through all this already, but just to make sure... – Ray O'Donnell Feb 13 '17 at 21:58
  • Most fonts which provide non-lining figures also provide lining ones. You may be able to [change which set of figures TCPDF uses from the font](https://stackoverflow.com/q/58505628/209139). – TRiG Oct 22 '19 at 13:48

1 Answers1

0

It can be done, but it's messy... In principle you'll have to do something like this:

  1. Break your text output into substrings where it changes from letters to numbers - probably using preg_split().
  2. Output the text with Cell() or MultiCell(), up to the point where the letters end and the numbers start.
  3. Raise the current Y-position using SetY().
  4. Output the numbers.
  5. Reset the Y-position to where it was before step 3 (assuming that you haven't crossed a line break).
  6. Repeat as necessary....

Of course, this raises the baseline for all numbers - from your sample it looks as if you need to raise the baseline for just some of them, which will be even more fiddly.

Good luck! :-)

Ray O'Donnell
  • 759
  • 4
  • 11
  • Thank you for your answer. I'm wondering if there is really no other way. If you take a closer look at for example the "1" in the images in my original post. You'll see that the 1 in the first image has an upside down T bottom. Do you know what I mean? In the second image it doesn't. So it turns out that it's not just a thing of stretching the font or use different baselines. Somewhere in the font must be a version of the glyph for the "1" which is rendered above the baseline and uses a fixed height. But how can I use that?! – datort Feb 14 '17 at 09:10
  • That's the only way I can think of - mind you, I started out using FPDF years ago, and my knowledge is based largely on that - TCPDF has way more functionality than FPDF ever had, so it's possible there's something in there I don't know about (I use it only intermittently). There are lots of examples in the TCPDF docs, so a detailed browse there may show something. – Ray O'Donnell Feb 14 '17 at 09:27
  • To use a specific character in the font, you'll probably have to specify it's numeric code explicitly - use whatever character map utility comes with your OS to find out what that is. if it was me, I'd just a different font - life's too short! :-) – Ray O'Donnell Feb 14 '17 at 09:32
  • @RayO'Donnell. Unicode doesn't distinguish lining and non-lining figures, so this isn't a matter of picking a different character, it's a matter of telling the font which of two optional glyphs to render for a given character. [I don't know whether that is possible in TCPDF](https://stackoverflow.com/q/58505628/209139). – TRiG Oct 22 '19 at 13:51