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?
You can use inch in your (print) CSS:
#foo { width: 5in; height: 3in; }
See length units in CSS.
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.
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.
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.
精彩评论