2013-04-04 49 views
4

问题是这样的 - 在Chrome中,此页面在一台计算机上正确保存为PDF,并且在另一台计算机上存在问题。 我有这样的代码:在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文件。

我在两台计算机上都使用Windows 7和最新版本的Chrome。

回答

0

您需要实现完整的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/

请让我知道这是否为你制定了:)