PdfContentByte canvas = writer.DirectContent; canvas.BeginText(); canvas.SetFontAndSize(font, fontSize); canvas.ShowText("Hello, world!"); canvas.EndText();
PdfContentByte canvas = writer.DirectContent; canvas.BeginText(); canvas.SetFontAndSize(font, fontSize); canvas.ShowTextAligned(Element.ALIGN_CENTER, "Hello, world!", x, y, 0); canvas.EndText();In this example, we are using the ShowTextAligned method to center the text horizontally and position it at a specific x and y coordinate on the page. The iTextSharp package library is a popular open-source library for working with PDF documents in C#.