Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 660
  • Last Modified:

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

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.
  • 2
1 Solution
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.
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.
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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now