问题是这样的-在Chrome中,这个页面在一台计算机上被正确地保存为PDF,而在另一台计算机上却有问题。我有这样的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body
{
margin:0; padding:0;
}
.fullscreen
{
width:1156px;
height:893px;
float:left;
background:url(2.jpg) no-repeat;
}
.firstpage{background:url(1.jpg) no-repeat;}
.lastpage{background:url(3.jpg) no-repeat;}
@media print {
body {
width:1156;
height:893;
}
}
</style>
</head>
<body>
<div class="fullscreen firstpage"></div>
<div class="fullscreen"></div>
<div class="fullscreen lastpage"></div>
</body>
</html>它只有3个div的3个不同的背景图像(相同的大小- 1156x893)。在我家里的电脑上,一切都很好。如果我放置@page{size:1156 893;}或者size:auto,或者(在本例中)我根本不放置它,这是没有区别的。
问题出在我的办公室电脑上,无论我做什么,打印模式下的页面大小始终是1286x909,并且内容会被缩放并移出页面。我是不是遗漏了什么,或者问题根本不在页面代码中?如果它不在代码中,我必须在哪里进行更改才能使其正确?如果有必要,我也可以提供2个PDF文件。
我在两台电脑上使用的都是Windows7和Chrome的最新版本。
发布于 2016-03-23 21:32:29
您需要为打印实现一个完整的css样式。
您为打印而编写的代码仅用于正文。
@media print {
body {
width:1156;
height:893;
}
}由于没有该css样式,浏览器将采用pdf的默认值。因此,如果你创建一个完整的css样式会更好,你可以在这篇文章中查看如何做到这一点。https://www.smashingmagazine.com/2011/11/how-to-set-up-a-print-style-sheet/
请让我知道这对你是否有效:)
https://stackoverflow.com/questions/15820638
复制相似问题