Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

Barcode Printing

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm having an issue with printing barcodes to my label printer from Java.

After quite the laundry list of failed attempts, which included using fonts, I've resorted to manually drawing the bars to the Graphics object, which works... except for one thing...
The entire barcode prints correctly to PDFs, laser-, and ink-jet printers. That's great, except I need it to print to the label printer correctly, which it doesn't.
My barcode, when printed on the label printer, doesn't print the last (width-2) bar.
The odd things is, when I print the PDF to the label printer, that end bar DOES print.

Since the draw output is exactly the same independently of which printer the barcode prints to (the barcode drawing algorithm doesn't perform any checks on the Graphics object), I'm at a loss as to why this is happening.

Any ideas?

Thanks.
 
Marshal
Posts: 67388
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wild-assed guess: over-running the printable area of the label printer?

(Welcome to the Ranch!)
 
Anthony Mann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Wild-assed guess: over-running the printable area of the label printer?

(Welcome to the Ranch!)


Unfortunately, I've already tried that... Like I said, it prints correctly when I send to the PDF, then manually send the PDF to the printer.

I suppose I could integrate that into my application, though. But that seems like I'm over-engineering things...

(Thanks!)
 
Saloon Keeper
Posts: 21967
149
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most common way to print barcodes is to use a barcode font. It's a lot less trouble than computing and rendering all the bars yourself.

When rendering anything near the edges of the print area, however, you are subject to clipping. Text renderers may clip entire letters, graphics renderers may just get stuff shaved off them. Your mileage may vary.

I think probably where you are running into grief has to do with the way that rendering and clipping are done. Printing is done within a 2-dimensional co-ordinate space whose actual dimensions are infinite (not really, but usually a lot bigger than the paper). The clipping mechanisms will then reduce the area that actually renders. There is, of course, the physical clipping that would occur when you attempt to print and your renderable region is physically larger than the page. Pixels fall off the edge, stuff fuzzes out, etc. You see stuff like this when you try and print a legal-sized document on a letter-sized page and it runs off the bottom.

Printers try and eliminate this action (partly because it's not good for the printer or the print quality) by defining a bounding box for rendering that's smaller than the physical page so that you only get the aforementioned overflow when the page in question isn't as big as the printer thinks it is. For some printers, there's physically no pixel-rendering elements outside a certain area, which itself is also a constraint.

Then there's the page size as defined by your app. Which is also applied. So the end result is the intersection rectangle of all of the preceding bounding boxes.

What I'm suspecting is that when you print a PDF, it's using a different bounding box for the PDF render area than your Java code is. You should be able to override the Java code's render area. If you are using brute-force print commands rather than the Java printing system, you may find that there's a hardware command you need to send to expand the print area.
 
Anthony Mann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what I get when I dump the PageFormats:


Here is my PrintProvider.print() method:


And here is my test class:


(and the dump method):


Why is the actual print method changing the pageformat? Is that a printer setting I need to fix?
 
Anthony Mann
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So after doing some more experimenting, I discovered that this line was causing the issue:



Which was returning the 2 inch media area. Removing that line fixed the print method getting the 2 inch area, which now causing the label to print out correctly.
 
Sheriff
Posts: 15520
263
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for sharing the resolution, Anthony
 
crispy bacon. crispy tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic