mPDF 隐藏 HTML 个元素

mPDF hiding HTML elements

我正在寻找一种方法来隐藏某些 HTML 元素,当 mPDF 从表单生成 PDF 时,它们不会呈现在 PDF 上,在本例中,div。

JavaScript 不适用于 mPDF 所以

visibility="hidden" 提交无效,display="none".

也无效

样式属性中的硬编码 visibility="hidden" 确实有效,但显然这会使元素无法使用。

编辑: 更多代码:

Div我想隐藏。

    <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";
}

但这不起作用。

我想通了。

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

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

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