简体   繁体   English

如何以 300 dpi 的分辨率打印 html 页面

[英]How can i print html page at 300 dpi resolution

i have a web page that encoded in html and css.我有一个用 html 和 css 编码的网页。 the size of the web page is of A4 Page (300dpi) = 2480 X 3508 (PX).网页尺寸为 A4 Page (300dpi) = 2480 X 3508 (PX)。

the problem is that when i print my web page it's printing in 72/96dpi resolution and print 7 pages instead of 1, and i want that the printer will print my web page in 300dpi resolution.问题是,当我打印网页时,它以 72/96dpi 分辨率打印并打印 7 页而不是 1 页,我希望打印机以 300dpi 分辨率打印我的网页。

some code in CSS, HTML, JAVASCRIPT or something that can help me? CSS、HTML、JAVASCRIPT 中的一些代码或可以帮助我的东西?

thanks.谢谢。

HTML/CSS are vector graphics. HTML/CSS 是矢量图形。 You have the css measurement unit "px" (which is always 72ppi and might therefore be a bit misleading) but it's not actually raster graphics - and it should hopefully be treated like vectors by the printer software.你有 css 测量单位“px”(它总是 72ppi,因此可能有点误导)但它实际上不是光栅图形 - 希望它应该被打印机软件视为矢量。 If you find lines, text and such printed in 72dpi you can be pretty sure the problem is your printer/renderer software.如果您发现以 72dpi 打印的线条、文本等,您可以确定问题出在您的打印机/渲染器软件上。 Try another browser or save it to PDF first (I know Chrome can do that natively).尝试使用其他浏览器或先将其保存为 PDF(我知道 Chrome 本身可以做到这一点)。

However since the CSS measurement unit "px" is 72ppi, raster graphics (=png, jpg and gif images) are always treated as 72ppi - even if they are saved in another resolution.然而,由于 CSS 测量单位“px”是 72ppi,光栅图形(=png、jpg 和 gif 图像)总是被视为 72ppi - 即使它们以其他分辨率保存。 But you can force images to the desired resolution by resizing them.但是您可以通过调整图像大小来强制图像达到所需的分辨率。 If I have an image that's 5x5 centimeters ( =2x2 inches ) I need to save it as 600x600px , but set its CSS width property to 144px (which is width*(72/300) ) to make it look like 5 centimeters on the website.如果我有一张5x5 centimeters=2x2 inches )的图像,我需要将它保存为600x600px ,但将其 CSS 宽度属性设置为144px (即width*(72/300) 144px width*(72/300) )以使其在网站上看起来像 5 厘米.

If the images are resized to the proper resolution you should be able to print it at 300dpi without any problems - especially if you save it to a pdf first.如果将图像调整为适当的分辨率,您应该能够以 300dpi 的分辨率打印而不会出现任何问题 - 特别是如果您先将其保存为 pdf。 Otherwise it's most likely the printer/printer software.否则很可能是打印机/打印机软件。

Keep in mind that web is not print and a webpage can't be expected to look exactly alike on screen and print - and that's the whole point.If that's what you're looking for you should just go with PDF instead.请记住,Web不是印刷品,并且不能期望网页在屏幕上和印刷品上看起来完全相同 - 这就是重点。如果这就是您要寻找的内容,您应该改用 PDF。

You can use CSS just like:你可以像这样使用 CSS:

@media print {
    @page {
        size: 210mm 297mm;
    }
}

or with px:或使用 px:

@media print {
    @page {
        size: 2480px 3508px;
    }
}

https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_types https://developer.mozilla.org/en-US/docs/Web/CSS/@media#media_types

Sorry for late response to print a ID card on 300 DPI in web page you need to convert your web page to PDF on 300 DPI.很抱歉在网页中以 300 DPI 打印身份证的迟到响应,您需要在 300 DPI 上将您的网页转换为 PDF。

For example in case of PHP and dompdf例如在 PHP 和 dompdf 的情况下

    $dompdf = new Dompdf(array('enable_remote' => true));
    $dompdf->set_option('dpi', 300);
    $dompdf->loadHtml($html);
    $dompdf->render();
    $dompdf->stream($filename.'.pdf',array('Attachment'=>0));

I made something similar using pdfkit but i think it has to be used with python or more specific i used it with django and it worked fine for me and created a 300dpi pdf Try this我使用 pdfkit 制作了类似的东西,但我认为它必须与 python 一起使用或更具体我将它与 django 一起使用,它对我来说很好用并创建了一个 300dpi pdf 试试这个

options = { 'page-size': 'Letter', 'margin-top': '0.75in', 'margin-right': '0.75in', 'margin-bottom': '0.75in', 'margin-left': '0.75in', 'encoding': "UTF-8", 'dpi': '300', 'custom-header' : [ ('Accept-Encoding', 'gzip') ] 'cookie': [ ('cookie-name1', 'cookie-value1'), ('cookie-name2', 'cookie-value2'), ], 'no-outline': None } options = { 'page-size': 'Letter', 'margin-top': '0.75in', 'margin-right': '0.75in', 'margin-bottom': '0.75in', 'margin-left ': '0.75in', 'encoding': "UTF-8", 'dpi': '300', 'custom-header' : [ ('Accept-Encoding', 'gzip') ] 'cookie': [ ( 'cookie-name1', 'cookie-value1'), ('cookie-name2', 'cookie-value2'), ], 'no-outline': None }

pdfkit.from_url(' http://google.com ', 'out.pdf', options=options) pdfkit.from_url(' http://google.com ', 'out.pdf', options=options)

https://github.com/JazzCore/python-pdfkit/blob/master/README.rst https://github.com/JazzCore/python-pdfkit/blob/master/README.rst

Unfortunately, web resolution is 72 dpi.不幸的是,网页分辨率为 72 dpi。 I believe this is an inherent setting in the browsers.我相信这是浏览器的固有设置。 If you adjust the browser's setting, or the printer's setting to "fit to page" when printing you might have some success.如果您在打印时将浏览器的设置或打印机的设置调整为“适合页面”,您可能会取得一些成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM