We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Bold Text Formatting

I started with the DrawingText sample. Everything is very clear however I cannot find a way to bold the text I am writing. Is this possible?

Please give response in VB and C# if possible.

4 Replies

DK Dhivya K Syncfusion Team September 26, 2006 12:54 PM UTC

Hi Jeffrey,

Thank you for your interest in Essential PDF.

We can bold the text in two ways:

1.In Grid model it can be done as follows:

CS:
//Sets the Font style
Font arialFont=new Font("Arial",10,FontStyle.Bold);
IPDFFont pdfFont = doc.Fonts.Add(arialFont);

VB:
''Sets the Font style
Dim arialFont As Font = New Font("Arial",10,FontStyle.Bold)
Dim pdfFont As IPDFFont = doc.Fonts.Add(arialFont)

Here is a sample for your reference:
TextFormatting_gridmodel.zip



2. In Flow model it can be done as follows.

CS:
//Sets the text as bold
textRange = paragraph.AppendText( "Bold Text_Bold Text" );
textRange.CharacterFormat.Bold = true;

VB:
''Sets the text as bold
textRange = paragraph.AppendText("Bold Text_Bold Text ")
textRange.CharacterFormat.Bold = True

Here is a sample for your reference.
TextFormatting.zip

Please take a look into the samples and let me know if you have any other queries.

Regards,
Dhivya.


AD Administrator Syncfusion Team September 29, 2006 03:04 PM UTC

Here is my code, how do I apply this bold setting using my existing code?

Private Function ToPDF(ByVal img As System.Drawing.Image) As String
''Create a new PDF Document. The pdfDoc object represents the PDF document.
''This document has one page by default and additional pages have to be added.
Dim pdfDoc As PDFDocument = New PDFDocument()

Dim properties As IPDFGraphicState = pdfDoc.CreateGraphicState()
properties.SplitImages = True

''Sets the BreakBehavior
properties.BreakBehavior = AutoBreakBehavior.Cropping

If Not img Is Nothing Then
pdfDoc.LastPage.Margins.All = 0
Dim dest As SizeF = New SizeF()
If img.Width > pdfDoc.LastPage.DrawingWidth Then
dest = New SizeF(pdfDoc.LastPage.DrawingWidth, -1)
Else
dest = New SizeF(img.Width, img.Height)
End If
pdfDoc.LastPage.Graphics.DrawImage(PointF.Empty, img, dest, properties)

End If

Dim path As String = "htmltopdf.pdf"
''Save the PDF Document to disk.
pdfDoc.Save(path, Response, HttpReadType.Open)
Return path
End Function


AD Administrator Syncfusion Team September 29, 2006 03:07 PM UTC

My apologies, I entered the wrong code. HEre is an excerpt of my code, please tell me how to apply the bold setting to it. It should look familiar, it was originally taken from an sample of yours.

Dim doc As PDFDocument = New PDFDocument()
Dim pdfFont As IPDFFont = doc.Fonts.Add(FontBaseFamily.Courier)

Dim props As IPDFGraphicState = doc.CreateGraphicState()

props.ForeColor = New PDFColor(0, 0, 0)
pdfFont.Size = 12






If SqlDataSource1.SelectCommand <> "" Then
Dim rows As SqlDataReader = SqlDataSource1.Select(DataSourceSelectArguments.Empty)
While (rows.Read())
If x = 0 Then
doc.LastPage.Graphics.DrawText(50, 20, rows(7) & rows(8), pdfFont, props)
doc.LastPage.Graphics.DrawText(50, 30, "Floorplan " & rows(9), pdfFont, props)


DK Dhivya K Syncfusion Team October 2, 2006 07:23 AM UTC

Hi Jeffrey,

I am able to reproduce the issue.The problem in your code is,you are trying to apply bold setting for predefined font. It is not possible to set bold style after creating the font.However,you can apply styles while creating the font as follows:

''Sets the Font style
Dim courierFont As Font = New Font("Courier New",10,FontStyle.Bold)
Dim pdfFont As IPDFFont = doc.Fonts.Add(courierFont)

Here is a sample:
TextFormatting.zip

Could you please replace the 2nd statement of your code["Dim pdfFont As IPDFFont = doc.Fonts.Add(FontBaseFamily.Courier) "] with the provided statements and let me know if the problem still exist.

Regards,
Dhivya.

Loader.
Live Chat Icon For mobile
Up arrow icon