Пример #1
0
 public static void main(String[] args) {
   try {
     if (args.length != 1) throw new IllegalArgumentException("Wrong number of arguments");
     FileReader in = new FileReader(args[0]);
     HardcopyWriter out = null;
     Frame f = new Frame("PrintFile: " + args[0]);
     f.setSize(200, 50);
     f.show();
     try {
       out = new HardcopyWriter(f, args[0], 10, .75, .75, .75, .75);
     } catch (HardcopyWriter.PrintCanceledException e) {
       System.exit(0);
     }
     f.setVisible(false);
     char[] buffer = new char[4096];
     int numchars;
     while ((numchars = in.read(buffer)) != -1) out.write(buffer, 0, numchars);
     out.close();
   } catch (Exception e) {
     System.err.println(e);
     System.err.println("Usage: java HardcopyWriter$PrintFile <filename>");
     System.exit(1);
   }
   System.exit(0);
 }
Пример #2
0
    /** Print the demo page */
    public void printDemoPage() {
      // Create the HardcopyWriter, using a 10 point font and 3/4" margins.
      HardcopyWriter hw;
      try {
        hw = new HardcopyWriter(this, "Demo Page", 14, .75, .75, .75, .75);
      } catch (HardcopyWriter.PrintCanceledException e) {
        return;
      }

      // Send output to it through a PrintWriter stream
      PrintWriter out = new PrintWriter(hw);

      // Figure out the size of the page
      int rows = hw.getLinesPerPage(), cols = hw.getCharactersPerLine();

      // Mark upper left and upper-right corners
      out.print("+");
      for (int i = 0; i < cols - 2; i++) out.print(" ");
      out.print("+");

      // Display a title
      hw.setFontStyle(Font.BOLD + Font.ITALIC);
      out.println("\n\n\n\t\tHardcopy Writer Demo Page\n\n\n\n\n");

      // Demonstrate font styles
      hw.setFontStyle(Font.BOLD);
      out.println("Font Styles:");
      int[] styles = {Font.PLAIN, Font.BOLD, Font.ITALIC, Font.ITALIC + Font.BOLD};
      for (int i = 0; i < styles.length; i++) {
        hw.setFontStyle(styles[i]);
        out.println("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
        out.println("1234567890!@#$%^&*()[]{}<>,.?:;+-=/\\`'\"_~|");
      }
      hw.setFontStyle(Font.PLAIN);
      out.println("\n\n");

      // Demonstrate tab stops
      hw.setFontStyle(Font.BOLD);
      out.println("Tab Stops:");
      hw.setFontStyle(Font.PLAIN);
      out.println("          1         2         3         4         5");
      out.println("01234567890123456789012345678901234567890123456789012345");
      out.println("^\t^\t^\t^\t^\t^\t^");
      out.println("\n\n");

      // Output some information about page dimensions and resolution
      hw.setFontStyle(Font.BOLD);
      out.println("Dimensions:");
      hw.setFontStyle(Font.PLAIN);
      out.println("\tResolution: " + hw.pagedpi + " dots per inch");
      out.println("\tPage width (pixels): " + hw.pagesize.width);
      out.println("\tPage height (pixels): " + hw.pagesize.height);
      out.println("\tWidth inside margins (pixels): " + hw.width);
      out.println("\tHeight inside margins (pixels): " + hw.height);
      out.println("\tCharacters per line: " + cols);
      out.println("\tLines per page: " + rows);

      // Skip down to the bottom of the page
      for (int i = 0; i < rows - 37; i++) out.println();
      // And mark the lower left and lower right
      out.print("+");
      for (int i = 0; i < cols - 2; i++) out.print(" ");
      out.print("+");

      // Close the output stream, forcing the page to be printed
      out.close();
    }