Add functionality for a PDF form filler that supports text auto-sizing/shrinking like Adobe:
Hi, Christopher,
Indeed, RadPdfViewer doesn't support such kind of functionality when a long text is inserted:
Even though this feature should be precisely implemented by our developers, an idea popped up in my mind which can try implementing. It is possible to change the font size dynamically for the activated editor. For this purpose, it is necessary to measure the text and determine the correct size.
Private Sub RadPdfViewer1_MouseUp(sender As Object, e As MouseEventArgs)
For Each visualPage As RadFixedPageElement In Me.RadPdfViewer1.PdfViewerElement.ViewElement.Children
For Each editorElement As RadElement In visualPage.Children
Dim tb As RadTextBoxControlElement = TryCast(editorElement, RadTextBoxControlElement)
If tb IsNot Nothing Then
font = tb.Font
RemoveHandler tb.TextChanged, AddressOf tb_TextChanged
AddHandler tb.TextChanged, AddressOf tb_TextChanged
End If
Next
Next
End Sub
Dim font As Font
Dim width As Double
Private Sub tb_TextChanged(sender As Object, e As System.EventArgs)
Dim tb As RadTextBoxControlElement = TryCast(sender, RadTextBoxControlElement)
Dim textToMeasure As String = tb.Text
Dim fontSize As Single = tb.Font.Size
Dim measured As SizeF = TextRenderer.MeasureText(textToMeasure, font)
width = tb.Size.Width
If measured.Width > width Then
Do
fontSize = fontSize - 1
font = New Font(tb.Font.FontFamily, fontSize, FontStyle.Regular)
measured = TextRenderer.MeasureText(textToMeasure, font)
Console.WriteLine(fontSize & " >> " & measured.Width & "available " & width)
Loop Until measured.Width < width
End If
tb.Font = font
End Sub
The achieved result is illustrated below:
Note that this is just a sample approach and it may not cover all possible cases. Feel free to modify and further extend it according to the specific requirements.
Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.