This is a migrated thread and some comments may be shown as answers.

Y position of the bottom of dynamically created elements

1 Answer 54 Views
PdfProcessing
This is a migrated thread and some comments may be shown as answers.
Jamie
Top achievements
Rank 1
Jamie asked on 04 May 2017, 03:51 PM

I'm struggling to see how to programmatically keep track of the relevant Y position to give to the FixedContentEditor after adding dynamically created elements such as tables and Text that can vary in height.

An example would be Drawing a Block that contains text from a SQL Query. This text could be one line long or 30 lines long and therefore the height of the text can vary greatly (below its in dtJobHeader.Rows(0).Item("Comment")). I need to be able to tell the editor.position.translate where it needs to move to and draw the next block after the previous block is drawn.

        editor.Position.Translate(defaultLeftIndent, currentTopOffset)
        editor.DrawBlock(DrawBlock(dtJobHeader.Rows(0).Item("Comment")), New Size(maxWidth, Double.PositiveInfinity))

        currentTopOffset += ????
        editor.Position.Translate(defaultLeftIndent, currentTopOffset)
        editor.DrawBlock(DrawBlock("Some Text Here, etc, etc, etc"), New Size(maxWidth, Double.PositiveInfinity))

Private Function DrawBlock(texttodraw As String) As Block

        Dim block As New Block()
        block.GraphicProperties.FillColor = RgbColors.Black
        block.HorizontalAlignment = HorizontalAlignment.Left
        block.TextProperties.Font = FontsRepository.Helvetica
        block.InsertText(texttodraw)

        Return block

 End Function


      

 

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 09 May 2017, 02:44 PM
Hi Jamie,

To achieve your requirement you can use the size of the block that holds the text. You can get the size using the Measure() method. In your scenario the code could look like this:
Dim block As Block = DrawBlock("Some Text Here, etc, etc, etc")
editor.DrawBlock(block, New Size(200, Double.PositiveInfinity))
 
Dim blockSize As Size = block.Measure()
currentTopOffset += blockSize.Height

Regards,
Martin
Telerik by Progress

Tags
PdfProcessing
Asked by
Jamie
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or