Path: blob/master/test/jdk/javax/print/attribute/URLPDFPrinting.java
41149 views
/*1* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22/*23* @test24* @bug 489977325* @summary Test for DocFlavor.URL.PDF support. No exception should be thrown.26* @run main URLPDFPrinting27*/2829import java.awt.*;30import javax.print.*;31import javax.print.attribute.standard.*;32import javax.print.attribute.*;33import java.io.*;34import java.util.Locale;35import java.net.URL;3637public class URLPDFPrinting {38/**39* Constructor40*/41public URLPDFPrinting() {42super();43}44/**45* Starts the application.46*/47public static void main(java.lang.String[] args) {48URLPDFPrinting pd = new URLPDFPrinting();49PrintService service[] = null, defService = null;5051service = PrintServiceLookup.lookupPrintServices(DocFlavor.URL.PDF, null);52if (service.length == 0) {53System.out.println("No PrintService support DocFlavor.URL.PDF");54return;55} else {56defService = service[0];57System.out.println("Print Service which supports DocFlavor.URL.PDF: "+defService);58}5960System.out.println("is DocFlavor.URL.PDF supported? "+defService.isDocFlavorSupported(DocFlavor.URL.PDF));61HashPrintRequestAttributeSet prSet = new HashPrintRequestAttributeSet();62prSet.add(new Destination(new File("./dest.prn").toURI()));6364DocPrintJob pj = defService.createPrintJob();65PrintDocument prDoc = new PrintDocument();66try {67pj.print(prDoc, prSet);68} catch (Exception e) {69e.printStackTrace();70}7172}73}7475class PrintDocument implements Doc {76InputStream fStream = null;77DocFlavor flavor = null;78HashDocAttributeSet docSet = new HashDocAttributeSet();79URL url = null;8081public PrintDocument() {82try {83url = PrintDocument.class.getResource("hello.pdf");84try{ Thread.sleep(6000); }catch(Exception e){ e.printStackTrace();}85fStream = url.openStream();86System.out.println("URL input stream "+fStream);87} catch(Exception e) {88e.printStackTrace();89}90docSet.add(OrientationRequested.LANDSCAPE);91}9293public DocAttributeSet getAttributes() {94System.out.println("getAttributes called");95return docSet;96}9798public DocFlavor getDocFlavor() {99System.out.println("getDocFlavor called");100return DocFlavor.URL.PDF;101}102103public Object getPrintData(){104System.out.println("getPrintData called");105return url;106}107108public Reader getReaderForText() {109return null;110}111112public InputStream getStreamForBytes() {113System.out.println("getStreamForBytes called");114return fStream;115}116}117118119