Bold text with DrawTextBox
Bold text with DrawTextBox
Hi,
I need to write text with DrawTextBox method but part of this text must be in bold. Bold text is variable in length because comes from user input, i.e:
This is a sample text with bold words.
Any help would be appreciated.
Thanks,
I need to write text with DrawTextBox method but part of this text must be in bold. Bold text is variable in length because comes from user input, i.e:
This is a sample text with bold words.
Any help would be appreciated.
Thanks,
-
- Posts: 352
- Joined: Tue Sep 27, 2011 11:47 am
Re: Bold text with DrawTextBox
Hi,
You can easily do that, all you have to do is set the resource font you want as bold, for example, create a font using https://www.gdpicture.com/guides/gdpicture/GdP ... FontU.html
and mark the Bold parameter as true.
Then use that font in DrawTextBox.
Hope this helps.
Best,
Sami
You can easily do that, all you have to do is set the resource font you want as bold, for example, create a font using https://www.gdpicture.com/guides/gdpicture/GdP ... FontU.html
and mark the Bold parameter as true.
Then use that font in DrawTextBox.
Hope this helps.
Best,
Sami
Re: Bold text with DrawTextBox
Hi,
Thanks for the quick answer, but your proposal writes all text in Bold whereas I need to write just some words in bold.
Other option would be to combine several calls to DrawTextBox with different fonts but then I would need to know the x,y coordinates where to place the next word.
Regards,
Thanks for the quick answer, but your proposal writes all text in Bold whereas I need to write just some words in bold.
Other option would be to combine several calls to DrawTextBox with different fonts but then I would need to know the x,y coordinates where to place the next word.
Regards,
Re: Bold text with DrawTextBox
Hi Puiguija
You can use the function GetTextWidth() to know the width taken by a text in a specified font.
See this simple sample in VbNet to how you can use it
Hope this help
Jean-Luc
You can use the function GetTextWidth() to know the width taken by a text in a specified font.
See this simple sample in VbNet to how you can use it
Code: Select all
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Pdf.NewPDF()
Pdf.NewPage(PdfPageSizes.PdfPageSizeA4)
Dim fntRegular As String = Pdf.AddStandardFont(PdfStandardFont.PdfStandardFontHelvetica)
Dim fntBold As String = Pdf.AddStandardFont(PdfStandardFont.PdfStandardFontHelveticaBold)
Pdf.SetOrigin(PdfOrigin.PdfOriginTopLeft)
Pdf.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
Dim PosX As Double
Dim PosY As Double
PosX = 10
PosY = 10
PosX = DrawText(fntRegular, PosX, PosY, 10, "This text is regular.")
PosX = DrawText(fntBold, PosX, PosY, 10, "This text is bold.")
PosX = DrawText(fntRegular, PosX, PosY, 10, "This text is regular.")
Pdf.SaveToFile("d:\test.pdf")
End Sub
Private Function DrawText(ByVal FntId As String, ByVal PosX As Double, ByVal PosY As Double, ByVal FntSize As Double, ByVal Text As String)
Pdf.SetTextSize(FntSize)
Pdf.DrawText(FntId, PosX, PosY, Text)
Return PosX + Pdf.GetTextWidth(FntId, FntSize, Text)
End Function
Jean-Luc
Re: Bold text with DrawTextBox
Thanks delbeke, that helped me a lot.
Re: Bold text with DrawTextBox
You are wellcome
Jean-Luc
Jean-Luc
Who is online
Users browsing this forum: No registered users and 1 guest