Skip to footer content

How to Convert Text to PDF in C#

In this comprehensive tutorial, we explore converting text files into PDF format using IronPDF within Visual Studio 2022. Start by ensuring you have the latest versions of both IronPDF and Visual Studio installed. We begin by reading text from a file located on the C drive using the File.ReadAllText method. Next, we initialize a new instance of the ChromePdfRenderer class. The text is then passed into the RenderHtmlAsPdf function, which facilitates the conversion to PDF format.

Additionally, we create a customized HTML stamp with red header style and white lettering, which can be tailored to individual preferences. The horizontal offset and vertical alignment properties are adjusted to position the stamp properly on the PDF document. This stamp is applied using the ApplyStamp method.

Finally, the converted PDF is saved as 'text_file_to_pdf.pdf' in the C drive. Remember to add your IronPDF license key to prevent watermarks. Upon executing the program, the text is successfully transformed into a PDF, complete with the customized HTML stamp. This tutorial demonstrates the simplicity and efficiency of using IronPDF to convert text to PDF, providing you with a valuable skill for document management.

Further Reading: How to Convert Text to PDF in C#

Chipego
Software Engineer
Chipego has a natural skill for listening that helps him to comprehend customer issues, and offer intelligent solutions. He joined the Iron Software team in 2023, after studying a Bachelor of Science in Information Technology. IronPDF and IronOCR are the two products Chipego has been focusing on, but his knowledge of all products is growing daily, as he finds new ways to support customers. He enjoys how collaborative life is at Iron Software, with team members from across the company bringing their varied experience to contribute to effective, innovative solutions. When Chipego is away from his desk, he can often be found enjoying a good book or playing football.