c# - How to reduce the font size while print notepad file from DOS using BAT file

07
2014-07
  • Suresh

    I am using DOS BAT file for print text file(bill).The problem is font size is too large so, its not fit in the paper size.The BAT Code is

    copy bill.txt \\127.0.0.1\bill exit

    please explain how to reduce the font size. And I am using c# for write in text file

  • Answers
  • Rik

    I'm going to assume the printer supports printing of command-codes (for example PCL). Most middle- & high-end printers do support printing of PCL.

    Before printing the text you need to send the commands to the printer to switch to a smaller font. You could even switch to landscape with commands (but that's probably not wanted with a bill).

    For most printers the standard font should be "Courier 12cpi". You can switch to a more condensed font of 17cpi. (For PCL you can find the commands here)

    You need to make a small textfile small.txt with the following code:

    <Esc>&k2S
    

    You need to replace the <Esc> with the actual escape character (being 0x1B or character 27).

    You can print your bill like this:

    copy small.txt+bill.txt \\127.0.0.1\bill
    exit
    

    You could even switch to a proportional font like "Univers" (this is like "Arial") and set the font size:

    <Esc>(s1p10v52T
    

    The (s1p stands for proportional printing, the 10v for the font size and 52T stands for "Univers". With this method you can choose the exact font-size. With the previous "Courier" you only have 10, 12 and 17 cpi.

    I should note however that normal textfiles align their text with spaces and expect every character to be the same width so if there are columns in the file they won't align properly.

    Edit: If you don't have an editor which supports escape codes you can do the following (but you could have written a small c# program):

    Make a textfile with the following (call it small.vbs):

    Wscript.Stdout.Write Chr(27)+"&k2S"
    

    Then execute the following on a command prompt:

    cscript /nologo small.vbs > small.txt
    

    This will result in a small.txt file which you can use with the copy command.

    Edit 2: It just occured to me to me that if it's not the width that a problem but the height of the text then you have no use switching to 17cpi because that still prints 6 lines per inch. Then you should switch your printer to 8 lines per inch with the following command:

    <Esc>&l8D
    

    So then adjust above method with cscipt. (change the "&k2S" in &l8D.)
    You could also do both (17cpi and 8 lines per inch)

    <Esc>&k2S<Esc>&l8D
    

    so make the small.txt like this:

    Wscript.Stdout.Write Chr(27)+"&k2S"+Chr(27)+"&l8D"
    
  • Enigman

    A lot would depend on the file itself. If your text file was designed for a landscape width and you are printing in portrait mode then the file would not fit properly.

    If you are opening the file in notepad then you can select the Format menu, then select Font to change the font size.

    Using the Format menu in Notepad will also give you the wordwrap option. This might also make a difference but could impact the output if you are epecting a specific spacing, alignment etc.

    You might need to print in Landscape instead of Portrait depending on the width of the text contained within your file.


  • Related Question

    How to delete many NotePad files quickly?
  • Questioner

    Hi Everyone I am trying to find out if there is a fast way to delete several (>10) Notepad files at the same time without going through the open file, delete file routine for each Notepad file? I am running Vista Home Premium Thank you.


  • Related Answers
  • ricbax

    What about selecting all the text files in the directory and using Shift + Delete keys

  • ricbax

    Open the folder that contains your "several Notepad files" (.txt I suppose), hold down the CTRL key and highlight each file you want to delete with a single left click. When done, hit DEL (or Shift + DEL to bypass the Recycle Bin).

  • outsideblasts

    Depends on the structure of the folder, but you could show DETAILS view, sort by (file) TYPE. Now all the .txt files are together and you can click the first, then SHIFT + click the last. All .txt files are now selected and just hit delete.