【问题标题】:mPDF hiding HTML elementsmPDF 隐藏 HTML 元素
【发布时间】:2015-07-17 13:17:13
【问题描述】:

我正在寻找一种方法来在 mPDF 从表单生成 PDF 时隐藏某些 HTML 元素,以便它们不会在 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";
}

但这不起作用。

【问题讨论】:

  • 如果我们能看到更多代码或 jsfiddle 会有所帮助

标签: javascript php html css mpdf


【解决方案1】:

我想通了。

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

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

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

【讨论】:

    猜你喜欢
    • 2015-03-20
    • 2011-12-04
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-04
    • 1970-01-01
    相关资源
    最近更新 更多