⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e701. the quintessential printing program using a streaming printing service.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
A streaming print service is used to convert print data from one format to another. Unlike a print service that prints to a printer, a streaming print service writes to an output stream. This example demonstrates a program that prints an image to a postscript-generating streaming print service. 
    import java.io.*;
    import javax.print.*;
    
    public class BasicStream {
        public static void main(String[] args) {
            try {
                // Open the image file
                InputStream is = new BufferedInputStream(
                    new FileInputStream("filename.gif"));
    
                // Prepare the output file to receive the postscript
                OutputStream fos = new BufferedOutputStream(
                    new FileOutputStream("filename.ps"));
    
                // Find a factory that can do the conversion
                DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
                StreamPrintServiceFactory[] factories =
                    StreamPrintServiceFactory.lookupStreamPrintServiceFactories(
                        flavor,
                        DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
    
                if (factories.length > 0) {
                    StreamPrintService service = factories[0].getPrintService(fos);
    
                    // Create the print job
                    DocPrintJob job = service.createPrintJob();
                    Doc doc = new SimpleDoc(is, flavor, null);
    
                    // Monitor print job events; for the implementation of PrintJobWatcher,
                    // see e702 Determining When a Print Job Has Finished
                    PrintJobWatcher pjDone = new PrintJobWatcher(job);
    
                    // Print it
                    job.print(doc, null);
    
                    // Wait for the print job to be done
                    pjDone.waitForDone();
                    // It is now safe to close the streams
                }
    
                is.close();
                fos.close();
            } catch (PrintException e) {
            } catch (IOException e) {
            }
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -