Created
May 2, 2017 19:46
-
-
Save samuelsonbrito/6d6d36d391602d77779ddbe50093bc74 to your computer and use it in GitHub Desktop.
Impressão no Java
This file contains hidden or 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.io.ByteArrayInputStream; | |
import java.io.InputStream; | |
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; | |
/** | |
* | |
* @author Samuelson Brito | |
*/ | |
public class Impressora { | |
public static void imprimir(String texto) { | |
DocFlavor df = DocFlavor.INPUT_STREAM.AUTOSENSE; | |
InputStream pis = new ByteArrayInputStream(texto.getBytes()); | |
Doc d = new SimpleDoc(pis, df, null); | |
PrintService p = PrintServiceLookup.lookupDefaultPrintService(); | |
if (p != null) { | |
DocPrintJob job = p.createPrintJob(); | |
try { | |
job.print(d, null); | |
} catch (PrintException e) { | |
System.err.println("Erro impressora:"+e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment