在打印java之前设置边距和字体?

在打印java之前设置边距和字体?,java,printing,Java,Printing,我想从txt文档中创建java打印服务,在打印之前需要在其中设置边距和字体 方法printjob工作正常,但产生的边距和字体不符合预期。如何解决我的问题? :( 对不起,我的英语:)谢谢你的帮助 public void test() { FileInputStream inStream = null; try { inStream = new FileInputStream("Test.txt");

我想从txt文档中创建java打印服务,在打印之前需要在其中设置边距和字体

方法
printjob
工作正常,但产生的边距和字体不符合预期。如何解决我的问题? :(
对不起,我的英语:)谢谢你的帮助

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);
            }
        }

您好…欢迎来到SO,要获得答案,您必须告诉我们您的问题在哪里,以及您迄今为止尝试了什么…请向我们展示您编码或得到的一些代码或错误!!:)@NoobEditor此链接我的代码请在您的问题中添加代码的相关部分。。。。。我的办公室代理不允许访问pastebin!!;)@NoobEditor我刚刚更新了我的代码请检查:D对不起,我找不到解决您问题的方法…当其他人没有发布解决方案时,请检查