打印时根本不显示隐藏图像

发布于 2025-01-21 15:57:47 字数 2262 浏览 3 评论 0原文

我有一些HTML可以在Chrome中打印。我想像真实纸一样以A4大小打印。当我在Chrome中打开HTML时,第二张图像显示了自身的一部分,但在打印到PDF时根本没有显示。如何使打印与HTML屏幕视图相同。

一些示例代码:我在HTML中使用的图像在Internet上。所有代码都在一个HTML文件中,只需复制HTML,然后您也可以预览它。

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        @page {
            size: A4;
            margin: 0;
        }

        body {
            margin: 0
        }

        .A4_page {
            margin: 0;
            overflow: hidden;
            position: relative;
            box-sizing: border-box;
            page-break-after: always;
            width: 210mm;
            height: 296mm;
            box-shadow: 0 .5mm 2mm rgba(0, 0, 0, .3);
        }

        /** For screen preview **/
        @media screen {
            body {
                background: #e0e0e0
            }

            .A4_page {
                background: white;
                box-shadow: 0 .5mm 2mm rgba(0, 0, 0, .3);
                margin: 5mm auto;
            }
        }

        @media print {
            .A4_page {
                width: 210mm
            }
        }
    </style>
</head>

<body>
    <div class="A4_page">
        <img style="margin-left: 40px" width="90%"
            src="https://papers.co/wallpaper/papers.co-nf48-sky-star-circle-space-night-sunset-blue-mountain-6-wallpaper.jpg?download=true"
            alt="">
        <img style="margin-left: 40px" width="60%"
            src="https://papers.co/wallpaper/papers.co-nf48-sky-star-circle-space-night-sunset-blue-mountain-6-wallpaper.jpg?download=true"
            alt="">
    </div>
</body>

</html>

屏幕视图: 打印视图:

I have some html to print in Chrome. I want to print it at A4 size like real paper. When I opened the html in chrome, the second image showed part of itself, but did not show at all when printing to PDF. How can I make the printing the same as html screen view.

Some example code: the image I use in the html is on the internet. All the code is in a single html file just copy the html then you can preview it too.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        @page {
            size: A4;
            margin: 0;
        }

        body {
            margin: 0
        }

        .A4_page {
            margin: 0;
            overflow: hidden;
            position: relative;
            box-sizing: border-box;
            page-break-after: always;
            width: 210mm;
            height: 296mm;
            box-shadow: 0 .5mm 2mm rgba(0, 0, 0, .3);
        }

        /** For screen preview **/
        @media screen {
            body {
                background: #e0e0e0
            }

            .A4_page {
                background: white;
                box-shadow: 0 .5mm 2mm rgba(0, 0, 0, .3);
                margin: 5mm auto;
            }
        }

        @media print {
            .A4_page {
                width: 210mm
            }
        }
    </style>
</head>

<body>
    <div class="A4_page">
        <img style="margin-left: 40px" width="90%"
            src="https://papers.co/wallpaper/papers.co-nf48-sky-star-circle-space-night-sunset-blue-mountain-6-wallpaper.jpg?download=true"
            alt="">
        <img style="margin-left: 40px" width="60%"
            src="https://papers.co/wallpaper/papers.co-nf48-sky-star-circle-space-night-sunset-blue-mountain-6-wallpaper.jpg?download=true"
            alt="">
    </div>
</body>

</html>

screen view:
enter image description here
print view:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云巢 2025-01-28 15:57:47

也许这样的事情会起作用?让我知道

@media print {
            .A4_page {
                width: 210mm;          
                display:inline-block;

            }
        }

Maybe something like this will work? let me know

@media print {
            .A4_page {
                width: 210mm;          
                display:inline-block;

            }
        }

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文