My requirement is to generate a pdf file using text file, for that used the below code.
Question: In my text file, there is a condition to apply page break, so please help me how to apply page break.
Code:
//read the source text file
TextReader tr = new StreamReader(@"Sample.txt");
//Instantiate a Document object by calling its empty constructor
Document doc = new Document();
//Add a new page in Pages collection of Document
Page page = doc.Pages.Add();
// Read the file till the end of the file has come
do
{
//Create a new text paragraph & pass text to its constructor as argument
TextFragment t2 = new TextFragment(tr.ReadLine());
// add the text object to paragraphs collection of section
if (t2.Text.Contains("\f"))
{
// need to apply page break here
}
page.Paragraphs.Add(t2);
// Read till the end of file
} while (tr.Peek() != -1);
// Close the StreamReader object
tr.Close();
//Save resultant PDF file
doc.Save(@"Sample File1.pdf");