Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
![]() |
HTML Text Alignment |
Post Reply ![]() |
Author | |
chris_adsi ![]() Team Player ![]() Joined: 19 May 21 Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() Posted: 19 May 22 at 4:23PM |
When I am rendering HTML Text using DrawHTMLText it seems to be adding some padding / spacing at the top of where I am expecting it to render. - about 5 to 10 points of measurement.
I am trying to render some HTML text alongside some other elements, and even with the same Top position it always renders lower. I can't make fixed adjustments though because the document is pretty dynamic so other content could flow, or be longer or shorter. Is it something in my text itself that I need to add / remove - I doubt I need to remove anything actually as I have stripped out all HTML tags as it still does it.
|
|
![]() |
|
kevinqpl ![]() Beginner ![]() Joined: 19 May 22 Status: Offline Points: 3 |
![]() ![]() ![]() ![]() ![]() |
Hi Chris, The DrawHTMLText function has to align all the text in each line along the baseline. This is quite a complex calculation when there are different fonts and font sizes. Each font has certain metrics, which are values stored in the font by the font designer. One of these values is the "line height", and another is the "descent". QPL works out the maximum height of all the blocks of text on each row, and then moves up by the maximum descent value. For historical reasons, the descent value is usually a negative number. Functions like DrawText use the baseline as the vertical reference point. So to get perfect alignment between DrawText and DrawHTMLText, you would need to subtract the text height and then add the descent. But because the descent is given as a negative number you actually have to subtract the text height and then subtract the descent. With the default origin at the bottom of the page, this bit of code should show how to get the alignment right: QP.DrawLine(0, 700, 500, 700); QP.DrawHTMLText(100, 700, 500, '<font size=24pt>This is some text'); QP.SetTextColor(1, 0, 0); QP.SetTextSize(24); QP.DrawText(100, 700 - QP.GetTextHeight - QP.GetTextDescent, 'This is some text'); |
|
![]() |
|
chris_adsi ![]() Team Player ![]() Joined: 19 May 21 Status: Offline Points: 23 |
![]() ![]() ![]() ![]() ![]() |
Brilliant - thanks for that - it makes sense but I would never have found that info elsewhere - really appreciate your detailed explanation.
We have built all our own document rendering engine with flow logic etc built in - often we have a pair of values to render side by side, with the tops aligned - like a prompt / label on left hand side of page, and then the detail / value to the right of it - all this is in a dynamic document so the positioning is always calculated on the fly. Sometimes we need formatting in either the label or the detail so we use HTML text so we can use bold / italics even superscript. We don't know if the label or the detail will be the longest pieces of text ether so we are always looking for the longest of the pair. I had converted all pairs to both be HTML text so at least the tops were in the same place, but then that just means some unneccessary markup in the fields that don't need any formatting (font size etc) - this info is invaluable - thanks!
|
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store