mPDF隐藏HTML元素


mPDF hiding HTML elements

我正在寻找一种方法来隐藏某些HTML元素,当mPDF从一个表单生成PDF,所以他们不呈现在PDF上,在这种情况下,一个div。

JavaScript不支持mPDF,所以

visibility="hidden" on submit不工作,display="none"也不工作。

在style属性中硬编码visibility="hidden"确实有效,但显然这会使元素不可用。

编辑:更多的代码:

Div I'm trying to hide.

    <div class="initial-container">
        <form id="initial" action="checkpage.php" method="post">
            <input type="hidden" id="page-num" name="page-num" value="1">
            <input type="text" class="initial" name="initials[]" placeholder="Initials" value="<?php if($initialsEntered == 'true'){ echo $initials; }  ?>">
            <input type="submit" class="submit" name="submit" value="Next Page" id="submit">
            <p class="page-num">Page 1/6</p>
        </form>
    </div>

在另一页生成PDF代码:

if(isset($_GET["pdf"])){
    $pdf = new mPDF('utf-8', '', '', '', 0, 0, 0, 0, 0, 0); 
    $pdf->SetDisplayMode('fullpage');
    $pdf->list_indent_first_level = 0;  // 1 or 0 - whether to indent the first level of a list
    $pages = ["page-one.php", "page-two.php", "page-three.php", "page-four.php", "page-five.php"];
    $pageCount = 0;
    while($pageCount < count($pages)){
        ob_start();
        include $pages[$pageCount]; 
        $template = ob_get_contents();
        ob_end_clean();
        $pdf->WriteHTML($template);
        $pdf->AddPage();
        $pageCount++;
    }
    $pdf->Output("probate-agreement.pdf", "I");
}

一开始我尝试:

get("submit").onclick = function(){
     get("initial-container").style.visibility = "hidden";
}

我明白了。

我只是用media="print"单独的CSS页面来隐藏特定的元素。我之前尝试过,但它没有工作,但现在我发现mPDF还不支持非块级元素的显示属性。

用块级元素包裹你想控制的任何元素,并在样式表中隐藏块元素:

<p class="hide-this">
    <input type="submit" class="what-i-want-to-hide">
</p>