-
-
Save Martin78b/4e6f68e5e4da00474c16e669c02fd88e 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
//HTML doc as input, an send to printer | |
public String ExtractTags(String html){ | |
//Change this tags to yours | |
String nameTag = "name"; | |
String memberTag = "member"; | |
String expTag = "exp"; | |
//String name = html.substring(html.indexOf("<html>") + 6, html.indexOf("</html")); | |
String label = "Name: "; | |
label =+ html.substring(html.indexOf("<"+nameTag+">") + 6, html.indexOf("</"+nameTag+"")); | |
label =+ "\nMember: #" + html.substring(html.indexOf("<"+memberTag+">") + 6, html.indexOf("</"+memberTag+"")); | |
label =+ " Exp: "html.substring(html.indexOf("<"+expTag+">") + 6, html.indexOf("</"+expTag+"")); | |
try { | |
PrintService mPrinter = null; | |
Boolean bFoundPrinter = false; | |
PrintService[] printServices = PrinterJob.lookupPrintServices(); | |
// | |
// Iterates the print services and print out its name. | |
// | |
for (PrintService printService : printServices) { | |
String sPrinterName = printService.getName(); | |
if (sPrinterName.equals("Zebra Labels Gt420")) { | |
mPrinter = printService; | |
bFoundPrinter = true; | |
} | |
} | |
InputStream is = new ByteArrayInputStream(label.getBytes()); | |
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE ; | |
// Find the default service | |
PrintService service = PrintServiceLookup.lookupDefaultPrintService(); | |
System.out.println(service); | |
// Create the print job | |
DocPrintJob job = service.createPrintJob(); | |
Doc doc= new SimpleDoc(is, flavor, null); | |
// Monitor print job events; for the implementation of PrintJobWatcher, | |
PrintJobWatcher pjDone = new PrintJobWatcher(job); | |
// Print it | |
job.print(doc, null); | |
// Wait for the print job to be done | |
pjDone.waitForDone(); | |
is.close(); | |
} catch (PrintException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment