1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
// write a program to generate a PDF file from a text file using iTextSharp.text; using iTextSharp.text.pdf; namespace PdfGenerator { class Program { static void Main(string[] args) { // Check if the text file exists if (!File.Exists("input.txt")) { Console.WriteLine("File not found"); return; } // Read the contents of the text file string text = File.ReadAllText("input.txt"); // Create a document Document document = new Document(PageSize.A4); PdfWriter writer = PdfWriter.GetInstance(document, new FileStream("output.pdf", FileMode.Create)); document.Open(); // Add the text to the document document.Add(new Paragraph(text)); // Close the document document.Close(); Console.WriteLine("PDF file generated successfully"); } } } |