Skip to content

How to add a page break when write to file

will he

Asked Feb 14, 2006, 7:10 AM EST5 answers
Share
LinkedInX
I am trying to write a file and I have to go to a new page when I write certain of records. Please help me and let me know how to add a page break when create file by writing records into the file. Thanks a lot!

Will

5 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    And what happends to be your files format? Plain text files does not have such thing as pages, hence they cannot include any page breaks.
    0
  • 0

    All what I try to do is When I convert the my txt file which is created by program into PDF file, I can force the one record be one page in PDF. Thanks.

    0
  • 0

    And if I did understand your problem correctly, you need to add page break information into your text file? In that case you have to add some special character sequence, that indicates a page break. For example "\p" or "<newPage>" or maby a '0xC'-character, which seems to be a "NP form feed, new page" character in ASCII table. Or one more elegant solution would be that you save your information in XML format, where it is easy to find each record.

    And the program that converts your txt to pdf, is it your own makings, or...? If it is, you simply look for your page break character sequence, and add a page break into the pdf. If it is not your own program, you should at least try for '0xC' character, and if it's not working, ask for converter manufacturer if there is a way to force a page break.

    In the case you are making that txt to pdf converter, you should check the PDF reference for details how to add a page break.

    0
  • 0

    Hi Guys,

    If you want to do it for text file simply use "\r\n" which will acts as page break.

    Check this out in action.

    1. Open a web application.
    2. Drag a button on the .aspx page.
    3. In the button click even copy the following code.

    private void Button1_Click(object sender, System.EventArgs e)
    {
     Response.ContentType ="text/ascii";
     Response.AddHeader( "Content-Disposition","attachment;filename=test.txt");

     string st="Hellow How are you \r\nIam fine \r\nHow abt You";
     Response.Write(st);
     Response.End();

    }

    Regards,
    Mohammed Sajid

    0
  • 0
    But but... \r\n is a line break, not a page break. If a record contains a line break, a page break is accindently placed to the pdf.
    0