Inserting a page Break in a text file by inserting FormFeed Character. Is this Universal solution?

可紊 提交于 2019-12-12 17:49:27

问题


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?


回答1:


Factors effecting Display and Print:

Display of formFeed on opening a txt file by a program depends on:

  • The Program's Interpretation of FormFeed character.

But Print operation result depends on:

  • Program used to open and Print txt file
  • The Printer we are using.

Form Feed Character handling by Various Programs:

1)NotePad:

  • Notepad is only text Editor and dont interpret Form Feed Character as pageBreak.
  • 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 :

  • Renders FormFeed character correctly as pageBreak.
  • On opening txt file with them Displays it as pageBreak and on printing also it acts as pagebreak.
  • We can also see Form Feed rendered as PageBreak in PrintPreview option in programs like WordPag/MS Word.

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:

  • when opened by notepad Unreadable symbol is shown as notepad cant render FormFeed character.

Point 2:

  • I got PageBreak in Print Preview as I used MS Word which renders formFeed correctly as Page Break.
  • But as already said some Printers might ignore it eventhough MS Word interprets it correctly and sends it for printing.

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



来源:https://stackoverflow.com/questions/35407896/inserting-a-page-break-in-a-text-file-by-inserting-formfeed-character-is-this-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!