html2pdf разрыв страницы после создания проблемы

Я хочу создать новую страницу, используя свойство css "page-break-after". Я выполнил все шаги, указанные в Разрыве страницы в Html2Pdf, но получаю следующую ошибку.

введите описание изображения здесь введите описание изображения здесь

Как видите ... 2-я страница начинается с того места, где закончилась первая ... Я хочу, чтобы 2-я страница начиналась сверху.

<?
/*
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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>&nbsp;</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>&nbsp;</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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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;
    }
}
?>

person Mustafa Mansoor    schedule 27.06.2013    source источник
comment
Вы можете поделиться своим PHP-кодом?   -  person Muhammad    schedule 27.06.2013
comment
я обновил свой вопрос с помощью кода php   -  person Mustafa Mansoor    schedule 28.06.2013
comment
$ _GET ['vuehtml'] содержит весь HTML ?? тогда почему бы вам не использовать объект DOM, объясните.   -  person Muhammad    schedule 28.06.2013
comment
no $ _GET ['vuehtml'] - это просто флаг режима отладки.   -  person Mustafa Mansoor    schedule 01.07.2013
comment
вы используете PAGE-BREAK-AFTER? это не ваш полный код, я не могу определить вашу проблему, не просмотрев весь ваш код. @ Mustafa Mansoor   -  person Muhammad    schedule 01.07.2013
comment
Я обновил свой полный код.   -  person Mustafa Mansoor    schedule 02.07.2013


Ответы (5)


Используйте теги page.

ex.

<page>
 content here.
</page>
person user3045072    schedule 27.12.2013
comment
Имейте в виду, что вам нужно переопределить page_header и page_footer в каждом <page>. - person naitsirch; 20.04.2016

В html2fpdf.php

искать это:

switch($tag){
  case 'PAGE_BREAK': //custom-tag
  case 'NEWPAGE': //custom-tag
      $this->blockjustfinished = true;
      $this->AddPage();
      break;

Вы видите, что вы можете использовать тег <NEWPAGE>, который определяет новую страницу или разрыв страницы.

Использую "<NEWPAGE>" работает корректно.

Я использую 'HTML2FPDF_VERSION','3.0(beta)'

person John Perge    schedule 20.09.2013

Если вы все еще хотите использовать

<div style="page-break-after: always;"></div>

вместо

<page>

вам также следует добавить $this->parsingCss->setPosition(); в _tag_close_DIV метод:

protected function _tag_close_DIV($param, $other='div')
    {
        if($this->parsingCss->value['page-break-after'] == "always") {
            $this->_setNewPage(null, '', null, $this->_defaultTop);
            $this->parsingCss->setPosition();
        }
person Łukasz Jakubiec    schedule 02.12.2014

У меня та же проблема, и я пробовал использовать разрыв страницы до и после разрыва страницы, оба с использованием тега 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]

Пример кода с использованием тега 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>";
person Jimbo    schedule 01.07.2013
comment
Да, я знаю. Я пытался сообщить вам, что я нахожусь в одной лодке с вами, и сообщал вам, что я пробовал. Я написал разработчику, но пока не получил ответа. - person Jimbo; 03.07.2013
comment
Мне сказали использовать тег ‹page›. Я пробовал. Поместите ‹page› в желаемое место разрыва страницы, а затем ‹/page› в конце страницы. Приведенный выше код изменится, как во втором примере. - person Jimbo; 08.07.2013

рассмотрите pagebreak: { mode: 'avoid-all'}, ниже пример варианта

 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' }

    };
person Vishnu    schedule 27.04.2020