title: Set margin and font before printing java?
body: <p>I want to create printing service in java from txt document in which i need to set margin and font before printing. </p>
  
  <p>Method <code>printjob</code> works fine but resulting margin and font is not as expected.How to resolve my problem ?
   :( <br />
  Sorry for my english :) Thank's before and for help</p>
  
  <pre><code>public void test() {
              FileInputStream inStream = null;
              try {
                  inStream = new FileInputStream("Test.txt");
              } catch (FileNotFoundException ffne) {
              }
              if (inStream == null) {
                  return;
              }
  
              DocFlavor psInFormat = DocFlavor.INPUT_STREAM.AUTOSENSE;
              Doc myDoc = new SimpleDoc(inStream, psInFormat, null);
  
              String printerName = "\\\\\\192.168.1.8\\EPSON L210 Series";
  
              PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
              printServiceAttributeSet.add(new PrinterName(printerName, null));
              PrintService[] printServices = PrinterJob.lookupPrintServices();
              System.out.println("printServices = " + printServices.length);
              System.out.println("printServices = " + printServices);
              PrintService defaultPrintservice = printServices[0];
              for (PrintService printService1 : printServices) {
                  System.out.println("printService1 = " + printService1.getName());
                  if (printService1.getName().contains("192.168.1.8")) {
                      defaultPrintservice = printService1;
                      break;
                  }
              }
  
              PrinterJob printerjob = PrinterJob.getPrinterJob();
              try {
                  printerjob.setPrintService(defaultPrintservice);
              } catch (PrinterException ex) {
                  Logger.getLogger(PrintingService.class.getName()).log(Level.SEVERE, null, ex);
              }
  
  
              DocPrintJob job = defaultPrintservice.createPrintJob();
  
              try {
                  PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
                  SimpleDoc simpleDoc = new SimpleDoc(inStream, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
                  aset.add(new Copies(1));
                  aset.add(MediaSizeName.ISO_A4);
                  aset.add(OrientationRequested.PORTRAIT);
                  aset.add(Sides.DUPLEX);
                  aset.add(JobSheets.NONE);
                  //aset.add((Attribute) DocFlavor.READER.TEXT_PLAIN);
                  job.print(simpleDoc, aset);
              } catch (PrintException ex) {
                  Logger.getLogger(PrintingService.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
  </code></pre>