我正在使用 css 来打破在新的 pdf 页面中打印所需的内容,我想在每个 pdf 页面上包含页眉/页脚,我尝试使用固定的 css/和边距,但这对第一页不起作用后续页。页脚与页面内容重叠..
mypage.php
<?php //call_db
//call_func
?>
<!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>My Print Page</title>
<style>
body {
background-color: white;
color: black;
font-size: small;
font-family: sans-serif, helvetica, tahoma, arial;
margin: 20%;
}
.page-break {
display:block;
page-break-before:always;
}
@media screen {
div.divFooter {
display: none;
}
div.divHeader {
display: none;
}
}
@media print {
div.divFooter {
position: fixed;
bottom: 0;
}
div.divHeader {
position: fixed;
top: 0;
}
}
</style>
<script type="text/javascript" src="jquery.js" > </script>
<script type="text/javascript">
$(document).ready(function(){
window.print();
});
</script>
</head>
<body>
//call sql query for content // A collection of 200 lists
<div class="divHeader"> <h1 align="center" style="font-size:36px;"> THE GAME OF THORNES</h1> </div>
<h1>Sean's CSS Print vs. Screen Example</h1>
<h2>Lesson 1</h2>
<p>This is my first Page in the document.</p>
<div class="page-break"></div>
<h2>Lesson 2</h2>
<p>Examples and theory of lesson2</p>
<div class="page-break"></div>
<h2>Lesson 3</h2>
<p>Examples and theory of lesson2</p>
<div class="divFooter">UNCLASSIFIED </div>
</body>
</html>
** 我正在添加 PHP 标签,就好像你有任何其他更好的方法来打印来自 db 的内容,请建议。
最佳答案
我认为这是这个 Convert HTML + CSS to PDF with PHP? 的副本, 您必须使用 pdf 转换器库将页眉和页脚添加到 pdf。
我习惯了http://www.tcpdf.org/在我的元素中。你也可以使用它。
关于php - 如何将 html 页面转换为 pdf 并在每个 pdf 页面中用标题打破内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24464115/