Adding text with baseline coords

Adding text with baseline coords

Forum member · Aug 1, 2006
Hi, Is it possible to add text to a pdf by specifying the coordinates of the baseline of the text ? Currently it seems that the origin of the coordinates is always the upper left corner of a text area. But I thought that the "native" way for PDF is to specify the coordinates of the baseline of the text. /tuomo

Re: Adding text with baseline coords

Forum member · Aug 1, 2006
Oh and just to clarify.. Currently I've managed to do this by setting the textareas y - coordinates to 0.9 * the font height. But this only works when there is only one line of text and it's all in the same font and size. The 0.9 was some magical multiplier we dug up by just trying out different values. By using the multiplier we got the coordinates to match those that Adobe's software reported for the original pdf. And what we were trying to do was to reproduce a pdf we had with the dynamic pdf library. /tuomo

Re: Adding text with baseline coords

Support · Aug 1, 2006
Hello Tuomo, The ascender is a value in the font and not always 90%. All TrueType or Type 1 fonts have a specific ascender value in them. So for example if you set the font size to 10 then the font will only drop 9 points and for font size of 20 it will drop 18 points. You can get these values using the GetAscender(fontSize) method of the Font object. So using this value you can calculate the starting point of your label by updating the Y coordinate but there is not other direct way to display the text on the baseline of your textarea. Thanks, ceTe Software Support Team

Re: Adding text with baseline coords

Forum member · Aug 1, 2006
Ok.. Then is it possible to give the coordinates from baseline for just one line of text ? If not, I think it seems a bit strange. Considering that it is the correct way to do it for PDFs. So it kind of sound you are going out of your way to hide the PDF specific stuff with your API but I think you should also provide methods to get "a bit close" to the PDF for advanced users... But no matter, I'll calculate the coordinates with the ascender and see if it works. I just kind of remembered that I tried it allready and didn't get correct results. But your library does not use any other magic to calculate the position except the ascender ? So basically I should get the correct position by substracting the ascender from the y - position ? Providing of course that there is only one line of text and that the font doesn't change on that one line.

Re: Adding text with baseline coords

Support · Aug 1, 2006
Hello, No, it is not directly possible to specify the co-ordinates from the baseline. You will have to calculate the value for the Y-coordinate based on the value returned from the GetAscender method of the Font object. This behavior is not being caused by our API but it is the default way the font behaves when added on the page. Our product does not use any calculations to place the text on the page. Thanks, ceTe Software Support Team

Re: Adding text with baseline coords

Forum member · Aug 1, 2006
Ok.. Thanks.. The ascender solution seems to work out ok so far. I'm just curious, how is it possible that your product doesn't do any calculations on the coordinates if PDF itself requires the text to be specified with the origin in lower left corner and the coordinates given are actually the coordinates of the baseline. So how is it possible that you add text with your API with specifying upper left coords and still you claim that you make no calculations to the coords in your API ? Sorry, not trying to be a nuisance, but I'm just interested.. /tuomo

Re: Adding text with baseline coords

Support · Aug 1, 2006
Hello Tuomo, Sorry for the confusion. When I say our product does not do any calculations, I meant to say that it does not calculate the Ascender and Descender values for the specified font. Our product uses the already predefined Ascender and Descender values within the font during the calculations for the placement of the text on the PDF page. Our product as you mentioned does perform calculations on the coordinates for the placement of the text but does not perform any calculations on the font's values. Thanks, ceTe Software Support Team

Re: Adding text with baseline coords

Forum member · Aug 2, 2006
Ok.. Thanks for the clarification. Any chance of getting the formulas you use for those calculations ? It is very important in our product that the text is put to exactly right place.

Re: Adding text with baseline coords

Support · Aug 2, 2006
Hello Tuomo, Assume the following: - Page is 1000 points (width) by 1000 points (height) - All margins are 50 points - The fonts ascender is 10 points - The fonts descender is 4 points If the labels x and y are 0, then the baseline for the first line will be at 60 points (Top margin + font ascender) from the top of the page and 50 points (Left margin) from the left edge of the page. If you need the values from the PDF coordinate space (which is calculated internally by our product) this will be 940 points from the bottom of the page (page height - 60 points) and 50 points from the left edge of the page. The second line of text in the label would be 14 points (fonts ascender + descneder) below the previous line. Thanks, ceTe Software Support Team