Php html2pdf创建问题后的分页符
我想使用css属性“page break after”创建新页面。我已遵循上给出的所有步骤,但出现以下错误 正如你所看到的。。。第二页从第一页结束的地方开始。。我想要第二页从上面开始Php html2pdf创建问题后的分页符,php,html2pdf,Php,Html2pdf,我想使用css属性“page break after”创建新页面。我已遵循上给出的所有步骤,但出现以下错误 正如你所看到的。。。第二页从第一页结束的地方开始。。我想要第二页从上面开始 <? /* Template Name: View Form */ include_once(ABSPATH."connection/localhost.php"); include_once(ABSPATH."include/cls_forms.php"); include_once(ABSPATH.
<?
/*
Template Name: View Form
*/
include_once(ABSPATH."connection/localhost.php");
include_once(ABSPATH."include/cls_forms.php");
include_once(ABSPATH."include/cls_fields.php");
//Authenticate("U");
$oFields = new Fields;
$oForm = new Forms;
$Title = $oForm->getFormTitleByID($_GET['form_id']);
$Content = $oForm->getFormContentByID($_GET['form_id']);
$isPleading = $oForm->getFormTypeByID($_GET['form_id']);
$FieldValues = $oForm->getUserFormFields($_SESSION['user_id'], $_GET['distinct_id']);
foreach($FieldValues as $Name => $Value)
{
$Content = str_replace("«".$Name."»", "<b>".$Value."</b>", $Content);
}
function filterMsWord($Content)
{
$Content = preg_replace("<([A-Za-z0-9\/]*):([A-Za-z0-9-\"=: ]*)>", "", $Content);
$Content = str_replace("<>", "", $Content);
return $Content;
}
if ($_GET['type'] == 'doc')
$Content = str_replace("[---pagebreak---]", '<br clear=all style="mso-special-character:line-break; page-break-before:always">', $Content);
elseif ($_GET['type'] == 'pdf')
$Content = str_replace("[---pagebreak---]", "<div class='page-break-before'></div><div class='page-break'></div>", $Content);
else
$Content = str_replace("[---pagebreak---]", "<div class='page-break'></div>", $Content);
if ($_GET['type'] == 'doc')
{
header("Content-type: application/vnd.ms-word");
header("Content-Disposition: attachment;Filename=".$Title.".doc");
}
else if ($_GET['type'] == 'pdf')
{
require_once(ABSPATH.'pdf/html2pdf.class.php');
ob_start();
}
?>
<!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>Preview Form</title>
<style>
.pleading-paper-size {
width: 6.35in !important;
max-width: 8.5in !important;
<? if ($_GET['type'] != 'pdf' and $_GET['type'] != 'doc') {?>
background-image: url(../images/pleading.jpg);
background-position: -0.5in 0;
background-repeat: repeat-y;
<? } ?>
padding-left: 1in !important;
padding-right: 1in !important;
<? if ($_GET['type'] != 'pdf') { ?>
line-height: 0.3242in !important;
<? } ?>
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
}
.normal {
width: <? if (!isset($_GET['type'])) { ?>6.0<? } else if ($_GET['type'] == 'doc') { ?>6.5<? } else { ?>5.0<? } ?>in !important;
text-align: left;
}
.page-break {
page-break-after: always;
page-break-inside: avoid;
clear:both;
}
page-break-before {
page-break-before: always;
page-break-inside: avoid;
clear:both;
}
p, td {
margin: 0 !important;
text-indent: 0 !important;
padding: 0 !important;
height: auto !important;
}
@media print {
.pleading-paper-size {
background-image: none;
}
}
</style>
<? if (isset($_GET['preview'])) { ?>
<script language="javascript">
function clearData(){
window.clipboardData.setData('text','')
}
function cldata(){
if(clipboardData){
clipboardData.clearData();
}
}
setInterval("cldata();", 1000);
</script>
<? $Body = ' ondragstart="return false;" onselectstart="return false;" oncontextmenu="return false;" onload="clearData();" onblur="clearData();" style="background-image: url('.ABSPATH.'images/PREVIEW.png);"';
} ?>
</head>
<body <?=$Body?>>
<? if (isset($_GET['preview'])) { ?>
<table class="<? if ($isPleading) { ?>pleading-paper-size<? } else { ?>normal<? } ?>" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><a href="javascript:void()" onclick="javascript: window.history.back()">
<input name="continue" type="button" value="Go Back" style="font-size:24px" />
</a> <a href="../addons/?distinct_id=<?=$_GET['distinct_id']?>">
<input name="continue" type="button" value="Continue to Next Step" style="font-size:24px" />
</a></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<? } ?>
<div class="<? if ($isPleading) { ?>pleading-paper-size<? } else { ?>normal<? } ?>">
<?=filterMsWord($Content)?>
</div>
<? if (isset($_GET['preview'])) { ?>
<table class="<? if ($isPleading) { ?>pleading-paper-size<? } else { ?>normal<? } ?>" border="0" cellspacing="0" cellpadding="0">
<tr>
<td> </td>
</tr>
<tr>
<td><a href="javascript:void()" onclick="javascript: window.history.back()">
<input name="continue" type="button" value="Go Back" style="font-size:24px" />
</a> <a href="../addons/?distinct_id=<?=$_GET['distinct_id']?>">
<input name="continue" type="button" value="Continue to Next Step" style="font-size:24px" />
</a></td>
</tr>
</table>
<? } ?>
</body>
</html>
<?
if ($_GET['type'] == 'pdf')
{
try
{
$html = ob_get_contents();
ob_end_clean();
$html2pdf = new HTML2PDF('P', 'A4', 'en');
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($html, isset($_GET['vuehtml']));
$html2pdf->Output($Title.'.pdf', 'D');
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
}
?>
预览表单
.诉状纸张尺寸{
宽度:6.35in!重要;
最大宽度:8.5英寸!重要;
背景图片:url(../images/conceding.jpg);
背景位置:-0.5英寸0;
背景重复:重复-y;
左侧填充:1英寸!重要;
右边填充:1英寸!重要;
线高:0.3242in!重要;
字体系列:Arial、Helvetica、无衬线字体;
字体大小:12px;
}
.正常{
宽度:6.06.55.0英寸!重要;
文本对齐:左对齐;
}
.分页符{
分页符后:始终;
内部分页符:避免;
明确:两者皆有;
}
前分页符{
前分页符:始终;
内部分页符:避免;
明确:两者皆有;
}
p、 运输署{
边距:0!重要;
文本缩进:0!重要;
填充:0!重要;
高度:自动!重要;
}
@媒体印刷品{
.诉状纸张尺寸{
背景图像:无;
}
}
函数clearData(){
window.clipboardData.setData('text','')
}
函数cldata(){
if(剪贴板数据){
clipboardData.clearData();
}
}
setInterval(“cldata();”,1000);
我也遇到了同样的问题,在使用DIV标记之前和之后都尝试过使用分页符。在分页符发生后,HTML2pdf类似乎没有重置下一行文本的垂直起点
示例代码:
(code for first page here)
// Supplement Schedule invoice page
$htmlfile[] = "<div style=\"page-break-before:always\"></div>";
$htmlfile[] = "<h1 style=\"text-align:center; margin-bottom:0; \">Supplement Estimate</h1>";
$htmlfile[] = "<h4 style=\"text-align:center; margin:0\">($visit->next_visit Weeks)</h4>";
[more code]
(此处第一页的代码)
//补充计划发票页
$htmlfile[]=“”;
$htmlfile[]=“补充估算”;
$htmlfile[]=“($visit->next_visit WORKS)”;
[更多代码]
使用page标记插入分页符的示例代码:
(code for first page here)
// Supplement Schedule invoice page
$htmlfile[] = "<page>";
$htmlfile[] = "<h1 style=\"text-align:center; margin-bottom:0; \">Supplement Estimate</h1>";
$htmlfile[] = "<h4 style=\"text-align:center; margin:0\">($visit->next_visit Weeks)</h4>";
[more code/text on the page]
$htmlfile[] = "</page>";
(此处第一页的代码)
//补充计划发票页
$htmlfile[]=“”;
$htmlfile[]=“补充估算”;
$htmlfile[]=“($visit->next_visit WORKS)”;
[页面上的更多代码/文本]
$htmlfile[]=“”;
我也遇到了同样的问题,我尝试过在使用DIV标记之前和之后使用分页符。在分页符发生后,HTML2pdf类似乎没有重置下一行文本的垂直起点
示例代码:
(code for first page here)
// Supplement Schedule invoice page
$htmlfile[] = "<div style=\"page-break-before:always\"></div>";
$htmlfile[] = "<h1 style=\"text-align:center; margin-bottom:0; \">Supplement Estimate</h1>";
$htmlfile[] = "<h4 style=\"text-align:center; margin:0\">($visit->next_visit Weeks)</h4>";
[more code]
(此处第一页的代码)
//补充计划发票页
$htmlfile[]=“”;
$htmlfile[]=“补充估算”;
$htmlfile[]=“($visit->next_visit WORKS)”;
[更多代码]
使用page标记插入分页符的示例代码:
(code for first page here)
// Supplement Schedule invoice page
$htmlfile[] = "<page>";
$htmlfile[] = "<h1 style=\"text-align:center; margin-bottom:0; \">Supplement Estimate</h1>";
$htmlfile[] = "<h4 style=\"text-align:center; margin:0\">($visit->next_visit Weeks)</h4>";
[more code/text on the page]
$htmlfile[] = "</page>";
(此处第一页的代码)
//补充计划发票页
$htmlfile[]=“”;
$htmlfile[]=“补充估算”;
$htmlfile[]=“($visit->next_visit WORKS)”;
[页面上的更多代码/文本]
$htmlfile[]=“”;
在html2pdf.php中
搜索此:
switch($tag){
case 'PAGE_BREAK': //custom-tag
case 'NEWPAGE': //custom-tag
$this->blockjustfinished = true;
$this->AddPage();
break;
您可以使用
标记定义新页面或分页符
我使用“
它工作正常
我在html2ffd.php中使用了'html2ffd_VERSION','3.0(beta)
搜索此:
switch($tag){
case 'PAGE_BREAK': //custom-tag
case 'NEWPAGE': //custom-tag
$this->blockjustfinished = true;
$this->AddPage();
break;
您可以使用
标记定义新页面或分页符
我使用“
它工作正常
我使用'HTML2FPDF_VERSION','3.0(beta)
使用页面标签
前
内容在这里。
使用页面标签
前
内容在这里。
如果仍要使用
<div style="page-break-after: always;"></div>
如果你还想用
<div style="page-break-after: always;"></div>
考虑pagebreak:{mode:'avoidall'}
,下面是示例选项
var opt = {
margin: 1, //top, left, buttom, right
filename: 'Initial_Contract.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {scale:2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
pagebreak: { mode: 'avoid-all', after: '.avoidThisRow' }
};
考虑pagebreak:{mode:'avoidall'}
,下面是示例选项
var opt = {
margin: 1, //top, left, buttom, right
filename: 'Initial_Contract.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: {scale:2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
pagebreak: { mode: 'avoid-all', after: '.avoidThisRow' }
};
你能分享你的php代码吗?我已经用php代码更新了我的问题$\u GET['vuehtml']包含所有html??那么为什么不使用DOM对象,explain.no$\u GET['vuehtml']只是调试模式的一个标志。是否使用分页符?这不是您的完整代码,如果不查看您的所有代码,我无法识别您的问题。@Mustafa Mansoorc您可以共享您的php代码吗?我已使用php代码更新了我的问题$\u GET['vuehtml']包含所有html??那么为什么不使用DOM对象,explain.no$\u GET['vuehtml']只是调试模式的一个标志。是否使用分页符?这不是您的完整代码,如果不查看您的所有代码,我无法识别您的问题。@Mustafa MansoorYes,我知道。我是想让你知道我和你在同一条船上,让你知道我做了什么。我写信给开发者,但还没有回音。有人告诉我使用标签。我试过了。放在所需的分页符位置,然后放在页面的末尾。上面的代码会像第二个示例中的代码一样更改。是的,我知道。我是想让你知道我和你在同一条船上,让你知道我做了什么。我写信给开发者,但还没有回音。有人告诉我使用标签。我试过了。放在所需的分页符位置,然后放在页面的末尾。上面的代码可能会像第二个示例中那样发生变化。请记住,您必须在每个
中重新定义页眉
和页脚
。请记住,您必须在每个
中重新定义页眉
和页脚
。