Android Question PDFWriter how to get text heights

Robert Valentino

Well-Known Member
Licensed User
I've been using the PDFWriter (v1.10) library to write / create PDFs

But I have been fudging the numbers. (Doing something and see if it looks right)

PDFWriter to write out text you need to do

mFontSize       as int = 12
mLeft              as Int = 20
mFromBottom as int = 200
mPaperSize      as int = mPDFPaperSize.LETTER_HEIGHT

mPDFWriter.setFont(mPDFFonts.SYMBOL,  mPDFFonts.COURIER)
mPDFWriter.setFont(mPDFFonts.SUBTYPE, mPDFFonts.COURIER)       

mPDFWriter.addText(mLeft, Abs(FromBottom-mPaperSize), mFontSize, "text to output")

To move to the next line I need to add some value to mFromBottom

How do I calculate the height for the font I have selected and size of font.

What I have been doing is this
      TextHeight     = (GetTextHeight("This is a text", 12) * 1.5)   ' Font size 12

Private Sub GetTextHeight(Text As String, TextSize As Int) As Int
  Dim FmtLabel  As Label
  Dim JavaObj  As JavaObject

  FmtLabel.TextSize = TextSize
  FmtLabel.Text  = Text

  JavaObj = FmtLabel
  JavaObj.RunMethod("setPadding",  Array As Object(0, 0, 0, 0))
  JavaObj.RunMethod("setIncludeFontPadding", Array As Object(False))

  Return mCanvas.MeasureStringHeight(FmtLabel.Text, FmtLabel.Typeface, FmtLabel.TextSize)
End Sub

If I want a small font like Ariel or Courier 16.6 is this going to work right.

ANY Help please