简体   繁体   English

mPDF隐藏HTML元素

[英]mPDF hiding HTML elements

I'm looking for a way to hide certain HTML elements when mPDF generates a PDF from a form so they do not render on the PDF, in this case, a div. 我正在寻找一种方法,当mPDF从表单生成PDF时隐藏某些HTML元素,以使它们不会呈现在PDF(在本例中为div)上。

JavaScript does not work with mPDF so JavaScript不适用于mPDF,因此

visibility="hidden" on submit does not work nor does display="none" . 提交时的visibility="hidden"不起作用,也不会display="none"

Hard-coding visibility="hidden" in a style attribute does work but obviously that would make the element unusable. 在style属性中硬编码visibility="hidden"确实有效,但显然会使元素不可用。

EDIT: More code: 编辑:更多代码:

Div I'm trying to hide. 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>

Generate PDF code on separate page: 在单独的页面上生成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");
}

At first I attempted: 首先,我尝试:

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

But this does not work. 但这是行不通的。

I figured it out. 我想到了。

I just used a separate CSS page with media="print" to hide specific elements. 我只是使用了一个单独的CSS页面,并带有media="print"来隐藏特定元素。 I attempted it before but it did not work, but now I found out that mPDF does not yet support the display property for non-block level elements. 我之前曾尝试过,但是没有用,但是现在我发现mPDF尚不支持非块级元素的显示属性。

Wrap whatever element you want to control with a block level element and hide the block element in the stylesheet: 用块级元素包装要控制的任何元素,然后在样式表中隐藏该块元素:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM