Z
Zach
In a txt file I would like to insert a character to force a page skip,
char 12 doesn't work, any suggestion?
Many thanks.
Zach
char 12 doesn't work, any suggestion?
Many thanks.
Zach
Zach said:In a txt file I would like to insert a character to force a page skip,
char 12 doesn't work, any suggestion?
Is there anything in the code below that might furnish a clue at to whyThat depends on the peripheral that interprets that file. If you are
pumping the file directly into a printer that supports character 12 as
"form feed", then it should work. If it doesn't, then either the printer
does not support that command, or the program that you wrote to send the
bytes from the file into the printer is doing something wrong and it is
not sending that character correctly.
Is there anything in the code below that might furnish a clue at to why
char 12 will not force a page skip?
Zach said:Is there anything in the code below that might furnish a clue at to why
char 12 will not force a page skip?
[...]
ev.Graphics.DrawString (line, printFont, Brushes.Black,leftMargin, yPos,
new StringFormat());
Thank you very much for your comprehensive response. After consideringZach said:Is there anything in the code below that might furnish a clue at to
why char 12 will not force a page skip?
[...]
ev.Graphics.DrawString (line, printFont, Brushes.Black,leftMargin,
yPos, new StringFormat());
Yes, you are not sending text to the printer; you are sending GRAPHICS.
If the text contains a char 12, it never gets sent to the printer;
instead, GDI+ tries to render a pixel-by-pixel representation of that
character, which most probably will result in a little square (unless
your printFont contains a symbol for char 12).
If you want to print with a PrintDocument object, and you want to skip
to the next page when the input file contains a char 12, you will have
to handle this situation in your code. Basically, you will have to scan
the "line" variable that you read from the file to see if it contains
tha char 12. If it does, you have to exit the loop that is printing
lines, and set ev.HasMorePages=true. Then you exit the PrintPage event
handler. The handler will be fired again immediately (due to the
ev.HasMorePages=true), and you should use it to continue printing from
the point where you exited the loop due to the char 12. The new lines
that you print will appear in a new page.
Note that this will take some programming work: you will need to
maintain some state variables outside of the event handler to keep track
of what you were doing and what you need to print next. It is not a
simple matter of just adding a single line of code and being done.
Also note that there *may* be an added difficculty in the part where you
scan the line for a char 12. Since you are reading through a
StreamReader, the characters get mapped through the default encoding. I
don't know right away if the char 12 will make it through the encoding
or not. If it doesn't, you may have to resort to reading the file
directly with a FileStream instead of a StreamReader.