using iTextSharp.text; using iTextSharp.text.pdf; var document = new Document(); var writer = PdfWriter.GetInstance(document, new FileStream("example.pdf", FileMode.Create)); document.Open(); var cb = writer.DirectContent; cb.BeginLayer(new PdfLayer("Layer 1", writer)); cb.SetFontAndSize(BaseFont.CreateFont(), 12); cb.ShowText("Hello World!"); cb.EndLayer(); document.Close();
using iTextSharp.text; using iTextSharp.text.pdf; var document = new Document(); var writer = PdfWriter.GetInstance(document, new FileStream("example.pdf", FileMode.Create)); document.Open(); var cb = writer.DirectContent; cb.BeginLayer(new PdfLayer("Layer 1", writer)); Image image = Image.GetInstance("image.jpg"); cb.AddImage(image); cb.EndLayer(); document.Close();In both examples, we have used the iTextSharp library to create a PDF document, added content to it, and then ended the layer using the EndLayer() method. This method is part of the PdfContentByte class which is part of the iTextSharp library.