1

I've been working with html2ps to get some text only labels to print correctly on a Dymo 450 Labelwriter printer. According to this page you should be able to resize the page using CSS. Here's the CSS I tried (in an external file and also tried it inline):

  @page {
      size: 28mm 85mm landscape;
      margin: 0mm;
  }

But the output postscript continues to be letter size. I was also able to do scaling using html2ps' -s option, but the margins are still so great that no text prints (just a blank label comes out)

html2ps -s .3 -L <url>

What can I do to get margins to zero and an output of the correct page size?

Here's a sample of the input html:

<div>Code: <b>SNHN1</b>&nbsp;&nbsp; PO: <b>035718</b>&nbsp;&nbsp;ln: <b>1</b><br>Desc: <div>US15 4" SOLID BRASS NO. 1 (SNHN1)******* HOUSE NUMBER SATIN NICKEL "1"<br></div>Remarks: <b>## CUSTOMER NAME 01/13</b><br><div>Vendor: HARDWARE COMPANY ETC...&nbsp;&nbsp; Rcvd: date and time...</div></div>

Also it appears html2ps is not respecting inline:

page-break-after:always;

Thanks for your help. I should also mention that I'm printing using lp from an ubuntu print server.

jjclarkson
  • 5,890
  • 6
  • 40
  • 62

1 Answers1

2

At work, we use wkhtmltoimage, part of the wkhtmltopdf project, for exactly this purpose. We're using a 400 and a Twin Turbo 400 instead of a 450. Shouldn't matter, I'd expect. They offer cross-platform statically compiled binaries, so no compiling is needed. Even then, an older version of wkhtmltopdf seems to be available in Universe.

In our case, we set the html and body sizes to specific pixel dimensions, calculated from the DPI of the printer, plus some fudge factor for CUPS. For example, when printing to the 30252 1.125x3.5 Address labels:

html, body {
    margin: 0px;
    border: 0px;
    padding: 0px;
    height: 290px;
    width: 958px !important;
    max-width: 958px !important;
    overflow: hidden;
}

These pixel dimensions were then matched with the proper command line switches to force a specific height and width. The resulting image can just be fed straight to the printer via lp or lpr. You can also turn the label sideways by changing the printing orientation (-o landscape or -o orientation-requested=N, see the docs) and swapping the dimensions.

You might need to manually specify the DPI of the image when passing it to CUPS. We do so expressly through -o ppi=300.

Charles
  • 50,943
  • 13
  • 104
  • 142
  • How does this work with multiple pages (multiple labels in the same file)? – jjclarkson Jan 16 '12 at 19:16
  • We've never *intentionally* done that. We generate one image per label, throw it at `lpr`, then generate the next image. If you generate an image with twice the dimensions in the proper axis, it *could* work properly, though it'll take quite a bit of fiddling to find just the right width and margins to get it to break in the right place without alignment annoyances. You might need to play with driver options as well. If the image is too large, the driver will either try to scale it down (bad) or print it across multiple labels (good). – Charles Jan 16 '12 at 19:19
  • I think I want to avoid using an image for this very reason. My output is all text and usually overflowing onto a second label would not be a problem for the few instances where my variable content may make that happen. I suppose I'll keep holding out for an answer that uses html2ps as I think this is a pretty versatile library for getting plain html into a print file. – jjclarkson Jan 16 '12 at 22:28