Search code examples
androidprintingdriverwireless

Generic printer driver - Android


I am trying to send some files (pdf files) to a network printer using an Android program I am developing but the printer is printing random characters instead of the actual document. Using a different app I was able to print to the same printer using what the app called a "generic printer drive. I could not find any generic printer drivers for android, so I was wondering if this is just an alias or if there exist generic drviers I can install on Android to use wireless printers.

The code I am using to send the file to the printer is:

Socket socket = new Socket();
try {
    socket.connect(new InetSocketAddress(IP, Port (9100)), 5000);
    BufferedOutputStream bos;

    bos = new BufferedOutputStream(socket.getOutputStream());
    InputStream in = new FileInputStream(new File (fileName));

    int c;
    byte[] bytes = new byte[1024];

    while ((c = in.read(bytes)) != -1) {
        bos.write(bytes, 0, c);
    }

    bos.flush();
    bos.close();
    socket.close();

} catch (IOException e) {
    e.printStackTrace();
}

Thanks!


Solution

  • Android has its own printing framework which is available from Android 4.4 (API level 19) on wards.

    However , if you would instead like to send a file directly to the printer, the file would need to be converted to an emulation which the printer understands like

    PCL6, BR-Script 3, IBM Pro-Printer XL, Epson FX-850
    

    The emulation your printer supports would be available in your printer documentation.

    Your Generic printer drive app works by converting the PDF to an image and then translates this image into an emulation your printer supports and sends it as bytes to the printer.