Html 如何将英寸转换为像素?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1999219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I convert inch to pixel?
提问by Moon
First of all, I am talking about HTML.
首先,我说的是 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?
我的客户让我制作一张他要用热敏打印机打印的表格。他告诉我热敏打印机使用 4x6'' 纸张。我应该在 CSS 上使用什么宽度和高度?
回答by stesch
You can use inch in your (print) CSS:
您可以在(打印)CSS 中使用英寸:
#foo { width: 5in; height: 3in; }
See length unitsin CSS.
参见CSS 中的长度单位。
回答by Carl Smotricz
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.
最简单的做法是在 CSS 代码中使用英寸度量,并希望从浏览器到打印机驱动程序再到打印机的软件链都知道并同意打印机的分辨率。
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.
从文档中或通过计算一英寸内的点数来实际确定打印机的分辨率需要更多的努力。然后,您可以将一个打印机点等同于一个像素,并继续以像素为单位进行 CSS 布局测量。
回答by xtofl
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.
您应该在 css 中使用6 pc
(即72 pt
)宽度作为@media: print
规则。高度... 根据内容,页数会有所不同。
回答by Pekka
If you mustuse HTML, use physical measurements as pointed out in the other questions.
如果您必须使用 HTML,请使用其他问题中指出的物理测量。
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.
但在我看来,从 HTML 打印标签是不明智的。HTML 不是为完成此任务所需的正确打印级别而构建的。考虑使用像fpdf这样的库生成 PDF ,它既简单又可靠。
回答by Rares Andreea
I used an online converter to convert pixels to inches for printing. I think that can help you: http://www.ninjaunits.com/convert-pixels-inches/You will need to select your output device to calculate dimensions by device's output DPI>
我使用在线转换器将像素转换为英寸以进行打印。我认为这可以帮助您:http: //www.ninjaunits.com/convert-pixels-inches/您需要选择您的输出设备以通过设备的输出 DPI 计算尺寸>
回答by Json
To convert inch to pixel you need to know DPI of your papers (Dot per pixel) Try: Inches to Pixels
回答by Adnan
You have an online converter at: http://tiporama.com/tools/pixels_inches.html
您有一个在线转换器:http: //tiporama.com/tools/pixels_inches.html
but still why are you doing this in HTML, you could generate your content into PDF.
但是你为什么要在 HTML 中这样做,你可以将你的内容生成为 PDF。