Printing to a label printer from a web-based Java application

Posted on 2005-03-16
Medium Priority
Last Modified: 2012-05-05
We have a Java-based web application, using Apache Tomcat as the server.  We want to be able to print to label printers using various sizes of label stock (significantly smaller than legal, letter, etc.).  

Additionally, because this is a label and not a whole document, we want the browser to ignore its header and footer settings.

Has anyone accomplished this, or heard of anyone who has?

When we print to our sample printer (a Brother P-touch QL500), one of two things happens:
If in Portrait mode, get one label with the browser's defined header and footer.
If in Landscape mode, get enough labels to make an 8.5" wide piece of paper (Page 1 of 27 and so on...)

Thank you.
Question by:ajraven
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Accepted Solution

boonleng earned 2000 total points
ID: 13562611
You can create a separate css for printing and set the layer to hidden when printing.

#header, #footer {
  display: none;

    <input:stylesheet href="/print_style.css" media="print"/>
<div id="header">Put header here</div>

<div id="label">Put label here</div>

<div id="footer">Put footer here</div>

A better way is to use JasperReports to design the label and export it to pdf file or JasperReport applet for printing, this will ensure you get the exact size and format you want.
LVL 10

Expert Comment

ID: 13570373
The information you want to change are browser settings. These cannot be controlled throught the web page. You'll find the settings for margins, headers and footers under file-page setup. In IE you'll also find a list of paper types and sizes there including "user defined," but I'm not sure how you define the size.
LVL 10

Expert Comment

ID: 13570397
I should mention there are two different types of headers: those create with <h1> thourgh <h6> and those added by the browser adding url, date, etc to the page. The later type are controlled by the user through Page Setup. The former would be controlled through a style sheet as Boonleng suggests.

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses
Course of the Month8 days, 10 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question