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 >
<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>
CodePudding user response:
Maybe something like this will work? let me know
@media print {
.A4_page {
width: 210mm;
display:inline-block;
}
}