How to get text run height

Product: PDFNetPython3 library (PDFTron SDK)

Product Version: 9.1.0

Please give a brief summary of your issue:
How to get text run height so I can accurately position it on the PDF page

Please describe your issue and provide steps to reproduce it:

I want to convert the intuitive xy screen coordinates shown for PDF elements in any PDF editor to page coordinates used by the PDFTron SDK to make the maintenance of dynamic elements’ xy coordinates easier. There are two differences:

  • the screen coordinate system origin is at the top left corner and the page coordinate system origin is at the bottom left corner.
  • the element’s xy coordinate is the top left corner of the element in PDF editors and in the bottom left corner of the element in PDFTron SDK

I solved the first issue using PDFView.view.ConvScreenPtToPagePt(), but I still need to solve the second one. It should be simple to do if I could get the height of the PDF element created by CreateTextRun(), but I found no method to do it in . I’m trying to implement something like:

# arbitrary screen XY coordinates
screen_x, screen_y = (0, 0)

page = pdf_doc.GetPage(page_number)
ewriter = ElementWriter()
ebuilder = ElementBuilder()
ewriter.WriteElement(ebuilder.CreateTextBegin(Font.Create(pdf_doc, Font.e_times_roman), 11))

page_position = view.ConvScreenPtToPagePt(
    Point(screen_x, screen_y), page_number
element = ebuilder.CreateTextRun("mytext")
element_height = .....
element.SetTextMatrix(1, 0, 0, 1, position.x, position.y - element_height)

Please provide a link to a minimal sample where the issue is reproducible:

You are looking for the Element.GetBBox API