Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top