Hello,
Thanks for your feedback. Below are my answers to your questions.
1. The PdfTextFinder interface provides properties for obtaining information such as font name, font size, etc. Sample code shown as below.
- Code: Select all
Dim page As PdfPageBase = doc.Pages(0)
Dim pdfTextFinder As New PdfTextFinder(page)
' Find text
Dim pdfTextFragments As List(Of PdfTextFragment) = pdfTextFinder.Find("keyword")
Dim find As PdfTextFragment = pdfTextFragments(0)
' Get font name
Dim fontName As String = find.TextStates(0).FontName
' Get font size
Dim fontSize As Single = find.TextStates(0).FontSize
2. You can define a rectangle, and then draw new text and set the alignment of the text within the rectangle. Please refer to the code below.
- Code: Select all
Dim rectangleF As New RectangleF(find.Bounds(0).Location, New SizeF(find.Bounds(0).Width + 10, fontSize + 10))
Dim pdfStringFormat As New PdfStringFormat()
' Horizontal alignment
pdfStringFormat.Alignment = PdfTextAlignment.Center
' Vertical alignment
pdfStringFormat.LineAlignment = PdfVerticalAlignment.Middle
pdfStringFormat.LineLimit = False
' Draw new text
page.Canvas.DrawString("newtext", New PdfTrueTypeFont(New Font(fontName, fontSize), True), PdfBrushes.Black, rectangleF, pdfStringFormat)
3. You can rotate the canvas before drawing the text to achieve the effect of vertical text.
- Code: Select all
page.Canvas.RotateTransform(90, find.Positions(0))
Sincerely,
Tommy
E-iceblue support team