Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
305 views
in Technique[技术] by (71.8m points)

android print html document on printer in same network

im trying to print Html document on printer from my android device which is in same network as printer.

This is sample code im trying to use. Im only able to print raw html on printer. Can someone help how to wrap that code to print html?

private String ipAdress, htmlContent; private int port;

public PrintBon(String ipAdress,int port, String content) {
    this.htmlContent = content;
    this.ipAdress = ipAdress;
    this.port = port;
}

public void print(){
    try
    {
        Socket sock = new Socket(ipAdress, port);
        PrintWriter oStream = new PrintWriter(sock.getOutputStream());
    
        //prints raw htmlContent
        oStream.println(htmlContent);
        oStream.println("


");
    
        //paper cut
        oStream.write(0x1D);
        oStream.write(86);
        oStream.write(48);
        oStream.write(0);

        oStream.close();
        sock.close();
    }
    catch(UnknownHostException e)
    {
        e.printStackTrace();
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
}

}

question from:https://stackoverflow.com/questions/65950556/android-print-html-document-on-printer-in-same-network

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...