Moon
Moon

Reputation: 22565

How do I convert inch to pixel?

First of all, I am talking about HTML.

My client asked me to make a form that he is going to print with a thermo printer. He told me that the thermo printer uses 4x6'' papers. What width and height should I use on CSS?

Upvotes: 2

Views: 25321

Answers (4)

Pekka
Pekka

Reputation: 449415

If you must use HTML, use physical measurements as pointed out in the other questions.

In my opinion though, printing labels is not wise to do from HTML. HTML is not built for the level of correct printing you need for this task. Consider generating a PDF using a library like fpdf, it's easy and reliable.

Upvotes: 1

stesch
stesch

Reputation: 7215

You can use inch in your (print) CSS:

#foo { width: 5in; height: 3in; }

See length units in CSS.

Upvotes: 13

xtofl
xtofl

Reputation: 41509

You should use 6 pc (i.e. 72 pt) width in your css for the @media: print rules. The height... Depending on the content, the number of pages will vary.

Upvotes: 2

Carl Smotricz
Carl Smotricz

Reputation: 67760

The simplest thing to do would be to use inch measurements in your CSS code, and hope that the chain of software from your browser to the printer driver to the printer all know about and agree on the printer's resolution.

It would be a little more effort to actually determine the resolution of the printer, either from its documentation or by counting dots in one inch. Then you could equate one printer dot to one pixel and continue to do your CSS layout measurements in pixels.

Upvotes: 3

Related Questions