Print Page | Close Window

DrawHTMLTextBox and text height

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: I need help - I can help
Forum Description: Problems and solutions while programming with the Debenu Quick PDF Library and Debenu PDF Viewer SDK
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=2190
Printed Date: 26 Jun 25 at 12:45PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: DrawHTMLTextBox and text height
Posted By: Jan
Subject: DrawHTMLTextBox and text height
Date Posted: 14 Mar 12 at 9:10AM

Hi, I have a file in XSL-FO format and I want convert it into PDF.
And I have problem with difference of text height calculated at drawing/printing via C#
and at insert in PDF file.
In both environment I use 'pt' units.

Example XSL-FO:
<fo:block line-height="14.399999999999999pt" top="11.0pt" left="41.0pt" height="15.0pt" width="434.0pt" font-family="Times New Roman" font-size="12.0pt">Test text, test text, test text .... </fo:block>

Inserting into PDF:

pdf.SetMeasurementUnits(0);     // 0 = 1/72 inch "per unit"
pdf.SetOrigin(1);

int idFont = pdf.AddTrueTypeFont("Times New Roman", 0);
pdf.SetHTMLNormalFont("Times New Roman", idFont);

string textHTML = "<p><font size=\"12pt\">Test text, test text, test text .... </font></p>";
pdf.DrawHTMLTextBox(10, 10, 434, 15, textHTML);

int _height = pdf.GetHTMLTextHeight(434, textHTML);

Height of text at C# drawing/printing is lower than 15 pt,
at inserting into PDF (variable _height) is higher than 15 pt (15,768 exactly).

Difference in this case is about 6%.
Solution may be reduce font size at PDF creating by 6% and round down to integer,
but I do not consider this the best solution.

Can you help me?
Thanks 




Replies:
Posted By: Jan
Date Posted: 19 Mar 12 at 12:26PM
I found, that value returned by GetHTMLTextHeight depends on value spacing parameter HTML text. Same single-line HTML text, same font, different spacing and different text height:
 
 
int iFontID = qp.AddTrueTypeFont("Times New Roman", 0);
qp.SetHTMLNormalFont("Times New Roman", iFontID);
string  textHTML = "<p spacing=\"-2pt\" align=\"left\"><font size=\"11pt\">Test text test text</font></p>";
qp.DrawHTMLTextBox(10, 350, 300, 200, textHTML);
double height = qp.GetHTMLTextHeight(300, textHTML);
textHTML = "<p spacing=\"2pt\" align=\"left\"><font size=\"11pt\">Test text test text</font></p>";
qp.DrawHTMLTextBox(10, 400, 300, 200, textHTML);
height = qp.GetHTMLTextHeight(300, textHTML);



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk