Inserting a page Break in a text file by inserting FormFeed Character using Java.
Is my solution universal or will it cause any problems?
Sample Code:
PrintWriter bof = response.getWriter(); // Obtained Writer from HTTP Response
bof.write("Para 1"); // Write 1st Para to printWriter
bof.write(new Character((char) 12).toString()); // Write Form Feed Character for Page Break
bof.write("Para 1"); // Write 2nd Para to printWriter
My Concerns: The Solution is working but below my 2 concenrs:
Point 1: Is there a way to hide Unknown symbol shown for FormFeed character in notepad ?
Point 2: I am currently opening the txt file with Word and checking the print Preview:
the Form Feed is actually making a page break as expected.
But are there any implications to this solution or will it work universally with all printers?
Factors effecting Display and Print:
Display
of formFeed on opening a txt file by a program depends on:But
Print operation
result depends on:Form Feed Character handling by Various Programs:
1)NotePad:
Hence when a txt file containing a formFeed Character:
when opened with Notepad >> It is displayed as Unreadable Symbol
When Printed after opening with NotePad : same unreadable Symbol is printed on paper.
2) Some
WordProcessors like WordPad/ Microsoft Word
/other 3rd party Editors :Universal Solution for getting PageBreak:
Some printers dont support Page Break by formFeed character and simply Ignores it irrespective of program used to open/print it.
Usage of
"/page" with RichTextFile(RTF) File is more Reliable/Universal solution
and works with most printers.With Rtf Files we can specify:
"/page" instead of "/f" for page Break and /par for lineBreak.
Rtf file is opened by default with Wordpad program in Windows.
Additional format control is possible
using Rtf file like:ex: particular font and font size (like Times New Roman size 10) can be specified.
In my Case Solution used is:
Point 1:
Point 2:
So I used rtf file instead of txt file and hence used "/page" instead of "/f" for more universal solution.
Below Hyperlink specifies info on how to create Rtf file and use /apge for page Break:
rtf File creation and using it for font and page Break Features