Articles in this section
Category / Section

How to create PDF document with underline text using C# and VB.NET?

8 mins read

The Syncfusion Essential® PDF is a .NET PDF library used to create, read, and edit PDF documents. Using this library, you can create the PDF document with underlined text using C# and VB.NET.

Steps to create PDF document with underlined text programmatically

  1. Create a new C# Console application project.

Create console application project

  1. Install the Syncfusion.Pdf.WinForms NuGet package as a reference to your .NET Framework application from nuget.org.

NuGet package reference

  1. Include the following namespaces in Program.cs file.

C#

using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System.Drawing;

 

VB.NET

Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports System.Drawing

 

  1. Use the following code sample to create a PDF document with underline text.

C#

//Create a new PDF document
PdfDocument document = new PdfDocument();
 
//Add a page to the document
PdfPage page = document.Pages.Add();
 
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
 
//Set the standard font with font style as underline 
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20, PdfFontStyle.Underline);
 
//Draw the text 
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, new PointF(0, 0));
 
//Save the document
document.Save("Output.pdf");
 
//Close the document
document.Close(true);
 
//This will open the PDF file so, the result will be seen in default PDF Viewer
Process.Start("Output.pdf");

 

VB.NET

'Create a new PDF document 
Dim document As PdfDocument = New PdfDocument()
 
'Add a page to the document 
Dim page As PdfPage = document.Pages.Add()
 
'Create PDF graphics for the page 
Dim graphics As PdfGraphics = page.Graphics
 
'Set the standard font with font style as underline  
Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, 20, PdfFontStyle.Underline)
 
'Draw the text  
graphics.DrawString("Hello World!!!", font, PdfBrushes.Black, New PointF(0, 0))
 
'Save the document 
document.Save("Output.pdf")
 
'Close the document 
document.Close(True)
 
'This will open the PDF file so, the result will be seen in default PDF Viewer 
Process.Start("Output.pdf")

 

A complete working sample can be download from UnderlineTextSample.zip.

 

By executing the program, you will get the output document as follows,

 

Output document reference

 

Task a moment to peruse the documentation. You can create the PDF document with different fonts (Standard, True type, CJK fonts, and OpenType fonts), RTL text, HTML styled text, RTF text, and Complex script language text.

 

Refer to here to explore a rich set of Syncfusion Essential® PDF features.

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from trial setup or the NuGet feed, include a license key in your product. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without trail message.

 

See Also:

 

Create PDF file in C# and VB.NET

Draw HTML styled text in PDF document using C# and VB.NET

Create PDF with CJK fonts

Render complex scripts in PDF


Conclusion

I hope you enjoyed learning about how to create PDF underline text using C# and VB NET.

You can refer to our WinForms PDF feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied