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.
Unfortunately, activation email could not send to your email. Please try again.

Bold Text Formatting

Thread ID:





49733 Sep 25,2006 08:41 PM Oct 2,2006 03:23 AM ASP.NET Web Forms (Classic) 4
Tags: PDF
Jeff Williams
Asked On September 25, 2006 08:41 PM

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.

Dhivya K [Syncfusion]
Replied On September 26, 2006 08:54 AM

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:

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

''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:

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

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

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

Here is a sample for your reference.

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


Administrator [Syncfusion]
Replied On September 29, 2006 11:04 AM

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)
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

Administrator [Syncfusion]
Replied On September 29, 2006 11:07 AM

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)

Dhivya K [Syncfusion]
Replied On October 2, 2006 03:23 AM

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:

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.



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.