question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image printing sometimes prints random characters

See original GitHub issue

When printing a ticket which has a logo, sometimes I get a bunch of random characters.

My code is packaged as an executable jar file My logo image is: 300 px width and 250 px height Thermal printer: Sanbee mini 58 mm Code sample

public class PrintTicket {
    private static BufferedImage logoImage = null;

    public void print(String printerName, List<String> processedData, String totalAmount, String id){
        PrintService printService = PrinterOutputStream.getPrintServiceByName(printerName);
        try {
            EscPos escpos = new EscPos(new PrinterOutputStream(printService));

            printImage(escpos);

            //... 

            escpos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void printImage(EscPos escPos) throws IOException {
        if (logoImage == null) {
            logoImage = ImageIO.read(Objects.requireNonNull(PrintTicket.class.getClassLoader()
                    .getResource("images/logo.jpeg")));
        }
        escPos.write(new RasterBitImageWrapper(), new EscPosImage(new CoffeeImageImpl(logoImage), new BitonalThreshold()));
        escPos.feed(1);
    }
}

As you can see I load the image just once the first time it is needed as a “BufferedImage”, my thinking (which was wrong) was that maybe the read operation was causing the issue. Any ideas on this?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
palanganerocommented, Nov 18, 2020

that happens to me too. once in five (more or less) instead of printing the image it prints random characters. But only by usb. By ethernet it always prints well. Is it the fault of my drivers and my printer?: https://postimg.cc/8sNF7BZx

0reactions
bruno-dicastrocommented, Oct 7, 2022

I’m facing the same problem, but it’s not related with this library. Did anyone, @AlbertoVillagomez or @palanganero, discovered what is causing this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

My Printer Is Printing Symbols - Small Business - Chron.com
When you see jumbled, random symbols on the page instead of the document content you expect, verify that you printed the file you...
Read more >
How to Fix Your Printer When It Starts Printing Gibberish
When your printer starts printing random characters and colors be sure to check out this video for information about how to fix this...
Read more >
How to Troubleshoot a Printer With Weird Characters - Azcentral
Sometimes, a print job simply gets stuck upon sending. This can occur for any number of reasons. The most important step you should...
Read more >
My Printer Is Printing Strange Characters | Techwalla
When an error occurs with data sent to a printer, the printer might print a document containing pages of strange symbols, random letters...
Read more >
SOLVED: Printer prints random characters - Fixya
sounds like a memory issues or a windows swap file problem. when printing large docs u need to have some free memory in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found