using (MemoryStream myMemoryStream = new MemoryStream())
{
Document myDocument = new Document();
PdfWriter myPDFWriter = PdfWriter.GetInstance(myDocument, myMemoryStream);
myDocument.Open();
PdfPTable table = new PdfPTable(2);
PdfPCell header = new PdfPCell(new Phrase("Your Heading"));
header.Colspan = 2;
header.HorizontalAlignment = 1;
table.AddCell(header);
table.AddCell("ID:" + Textbox1.Text);
myDocument.Add(table);
myDocument.Close();
byte[] content = myMemoryStream.ToArray();
using (FileStream fs = File.Create("C:\\Test.pdf"))
{
fs.Write(content, 0, (int)content.Length);
}
}
When you close your form you can delete the file
File.Delete(C:\\Test.pdf);