Created
July 19, 2011 23:20
-
-
Save anonymous/1093987 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.logging.Level; | |
import java.util.logging.Logger; | |
import javax.print.Doc; | |
import javax.print.DocFlavor; | |
import javax.print.DocPrintJob; | |
import javax.print.PrintException; | |
import javax.print.PrintService; | |
import javax.print.PrintServiceLookup; | |
import javax.print.SimpleDoc; | |
public class print { | |
public static void main() | |
{ | |
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PDF; | |
PrintService[] services = | |
PrintServiceLookup.lookupPrintServices(flavor, | |
null); | |
Object pdfBytes = null; | |
if (services.length>0) | |
{ | |
DocPrintJob printJob = services[0].createPrintJob(); | |
Doc document = new SimpleDoc(pdfBytes,flavor,null); | |
try { | |
printJob.print(document, null); | |
} catch (PrintException ex) { | |
Logger.getLogger(print.class.getName()).log(Level.SEVERE, null, ex); | |
} | |
} else { | |
System.out.println("no pdf printer available"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment